-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
performance on clamp #179
Comments
I don't understand what the benchmarks above are intended for.:confused: Is this what you mean? julia> @btime clamp!($(zeros(N0f8, 512, 512)), 0.1, 0.9);
505.900 μs (0 allocations: 0 bytes)
julia> @btime clamp!($(zeros(N0f8, 512, 512)), 0.1N0f8, 0.9N0f8);
114.299 μs (0 allocations: 0 bytes)
julia> @btime clamp.($(zeros(N0f8, 512, 512)), 0.1, 0.9);
687.300 μs (2 allocations: 2.00 MiB)
julia> @btime clamp.($(zeros(N0f8, 512, 512)), 0.1N0f8, 0.9N0f8);
179.200 μs (2 allocations: 256.14 KiB) Yes, I also think it can be optimized (specialized) as follows: Base.clamp(x::X, lo::X, hi::X) where X<:FixedPoint = X(clamp(x.i, lo.i, hi.i), 0) However, the bottleneck should be identified first. I don't think floating-point conversions are "too" slow. They are inherently expensive. |
I was thinking a specification like this: Base.clamp(x::X, lo, hi) where X<:FixedPoint = clamp(x, X(lo), X(hi)) I opened this as a potential issue tracker and haven't spent some time playing with it, feel free to close it if you think this makes non-sense. |
This issue clearly makes sense, but I don't know what you want. |
TBH, I had believed that the optimization for |
Oh, I wrote this done as a quick note to myself and I didn't spend enough time playing with it, I'm sorry I didn't make it clear.
I was meant to say "I believe this performance gap is expected, but I think there're merits to proactively convert I'm in a bit of a hurry catching up with my own ddls, I'll post the update later if I find anything worth optimizing.
I don't quite understand the reasoning behind this, can you clarify it a bit? Thanks. My understanding is that in-place functions in Base are worth extending. |
The specialization of many "in-place" methods requires much labor and offers little benefit.
I agree with you. Therefore, I think Also, if we follow the philosophy, |
Certainly the specialization in #179 (comment) makes sense. The one in #179 (comment) is much more dangerous, since currently Cases like |
I merged PR #194. If we try to improve it further I will keep this issue open, otherwise I will close this issue. |
Thanks for working on this. #194 looks like a good-enough improvement to me. |
This is expected, but I think it can be optimized.
Ref: observed in JuliaImages/ImageContrastAdjustment.jl#28 (comment)
The text was updated successfully, but these errors were encountered: