Skip to content
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

algorithms/GenericFunctions: x == 0 -> iszero(x) #1869

Merged
merged 3 commits into from
Oct 18, 2024

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Oct 18, 2024

Updates #1868

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.15%. Comparing base (5ffdd2d) to head (186416a).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1869      +/-   ##
==========================================
- Coverage   88.17%   88.15%   -0.02%     
==========================================
  Files         120      120              
  Lines       30220    30250      +30     
==========================================
+ Hits        26645    26668      +23     
- Misses       3575     3582       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thofma
Copy link
Member

thofma commented Oct 18, 2024

Sorry, I should have just written it here once. I don't think this is an improvement.

@fingolfin
Copy link
Member

It is measurably an improvement in terms of performance (of course! we know that), albeit a very small one:

julia> x = big(5)
5

julia> @benchmark iszero($x)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  2.125 ns … 5.708 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     2.208 ns             ┊ GC (median):    0.00%
 Time  (mean ± σ):   2.196 ns ± 0.049 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

             █          ▇▁
  ▂▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▂ ▂
  2.12 ns        Histogram: frequency by time       2.33 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark $x == 0
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  2.708 ns … 17.500 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     2.833 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   2.830 ns ±  0.168 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

         ▁      ▇      █       ▃      ▃      ▂      ▂        ▂
  ▄▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁▆ █
  2.71 ns      Histogram: log(frequency) by time     3.04 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

So one can of course argue whether it is worth it in these situations.

Then again, why not take advantage of this, however minor it may be? The code isn't harder to read one way or the other, is it?

Whether the code looks better one way or another is a matter of taste?

@thofma
Copy link
Member

thofma commented Oct 18, 2024

Ah sorry, I was not thinking about BigInt case. Everything is fine then.

@fingolfin fingolfin enabled auto-merge (squash) October 18, 2024 14:42
@fingolfin fingolfin merged commit 8a5d2d2 into Nemocas:master Oct 18, 2024
29 of 30 checks passed
@nsajko nsajko deleted the iszero_algorithms_GenericFunctions branch October 18, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants