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

Less accurate answers than BenchmarkTools on some microbenchmarks #74

Closed
LilithHafner opened this issue Mar 8, 2024 · 0 comments · Fixed by #75
Closed

Less accurate answers than BenchmarkTools on some microbenchmarks #74

LilithHafner opened this issue Mar 8, 2024 · 0 comments · Fixed by #75
Labels
bug Something isn't working timing results

Comments

@LilithHafner
Copy link
Owner

g is a little faster than f, as justified by these macrobenchmarks and analysis of generated code. Chairmarks fails to detect this while BenchmarkTools succeeds.

Originally reported by @matthias314 here with macrobenchmarks by @MasonProtter here

julia> function macro_benchmark_5!(out, f)
           for j  axes(out, 2)
               x = UInt128(j)
               for i  axes(out, 1)
                   out[i, j] = f(x, i)
               end
           end
       end;

julia> function macro_benchmark_5_noinline!(out, f)
           for j  axes(out, 2)
               x = UInt128(j)
               for i  axes(out, 1)
                   out[i, j] = @noinline f(x, i)
               end
           end
       end;

julia> function macro_benchmark_6!(f, N)
           for j  1:N
               x = UInt128(j)
               for i  1:N
                   Base.donotdelete(f(x, i))
               end
           end
       end;

julia> function macro_benchmark_6_noinline!(f, N)
           for j  1:N
               x = UInt128(j)
               for i  1:N
                   Base.donotdelete(@noinline f(x, i))
               end
           end
       end;

julia> f(x, n) = x << n;

julia> g(x, n) = x << (n & 63);

julia> let
           out = Matrix{UInt128}(undef, 10_000, 10_000)
           @time macro_benchmark_5!(out, f)
           @time macro_benchmark_5!(out, g)
           println()
           @time macro_benchmark_5_noinline!(out, f)
           @time macro_benchmark_5_noinline!(out, g)
           println()
           @time macro_benchmark_6!(f, 10_000)
           @time macro_benchmark_6!(g, 10_000)
           println()
           @time macro_benchmark_6_noinline!(f, 10_000)
           @time macro_benchmark_6_noinline!(g, 10_000)
       end
  0.185143 seconds
  0.121225 seconds

  0.220452 seconds
  0.181451 seconds

  0.114753 seconds
  0.115903 seconds

  0.258359 seconds
  0.204093 seconds

julia> x = UInt128(1); n = 1;

julia> @btime f($x, $n);
  2.500 ns (0 allocations: 0 bytes)

julia> @btime g($x, $n);
  1.958 ns (0 allocations: 0 bytes)

julia> @b f($x, $n)
1.137 ns

julia> @b g($x, $n)
1.137 ns
@LilithHafner LilithHafner added the bug Something isn't working label Mar 8, 2024
@LilithHafner LilithHafner linked a pull request Mar 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working timing results
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant