From fa58f508788a572a1ecac9d8dbfe069fe2add4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= Date: Mon, 19 Apr 2021 18:47:04 +0200 Subject: [PATCH] Fix hygiene-related bug with Julia 1.6.0 Fixes: #32 --- CHANGELOG.md | 10 +++++++++- Project.toml | 2 +- src/count_ops.jl | 18 ++++++++++++------ test/runtests.jl | 26 +++++++------------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d33dc2..c29f07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.5] - 2021-04-19 + +This is a bugfix release. + +### Changed + +- Fix hygiene-related bug with Julia 1.6.0 (#32, #33) + ## [0.1.4] - 2021-04-13 @@ -13,7 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - Fix CI issues (#22) -- Compatibility with `CompatBounds.jl` 0.12 (#29) +- Compatibility with `PrettyTables.jl` 0.12 (#29) diff --git a/Project.toml b/Project.toml index 0c06796..644030c 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "GFlops" uuid = "2ea8233c-34d4-5acc-88b4-02f326385bcc" license = "MIT" authors = ["François Févotte "] -version = "0.1.4" +version = "0.1.5" [deps] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" diff --git a/src/count_ops.jl b/src/count_ops.jl index 81de23e..8ebac70 100644 --- a/src/count_ops.jl +++ b/src/count_ops.jl @@ -37,19 +37,25 @@ end +# Helper accessor (that can be overriden to fake benchmarking times in tests) +times(t::BenchmarkTools.Trial) = t.times macro gflops(funcall) + benchmark = quote + $BenchmarkTools.@benchmark $funcall + end + quote let - b = @benchmark $funcall - ns = minimum(b.times) + b = $(esc(benchmark)) + ns = minimum(times(b)) cnt = flop($(count_ops(funcall))) - gflops = cnt/ns - peakfraction = 1e9*gflops / peakflops() - memory = $(GFlops.BenchmarkTools).prettymemory(b.memory) + gflops = cnt / ns + peakfraction = 1e9 * gflops / peakflops() + memory = $BenchmarkTools.prettymemory(b.memory) @printf(" %.2f GFlops, %.2f%% peak (%.2e flop, %.2e s, %d alloc: %s)\n", - gflops, peakfraction*100, cnt, ns*1e-9, + gflops, peakfraction*100, cnt, ns*1e-9, b.allocs, memory) gflops end diff --git a/test/runtests.jl b/test/runtests.jl index c023a89..6244c2a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,21 +20,9 @@ function my_prod(m, v) res end -import BenchmarkTools: @benchmark -struct FakeResults - times - allocs - memory -end -macro benchmark(e) - quote - FakeResults(#= times =# [2.0, 3.0], - #= allocs =# 1, - #= memory =# 1042) - end -end - - +# Fake benchmarked times +import BenchmarkTools +GFlops.times(::BenchmarkTools.Trial) = [2.0, 3.0] @testset "GFlops" begin @testset "Counter" begin @@ -128,7 +116,7 @@ end @test GFlops.flop(cnt) == 1 end end - + @testset "sqrt" begin let cnt = @count_ops sqrt(4.2) @test cnt.sqrt64 == 1 @@ -219,15 +207,15 @@ end x = rand(N) y = Vector{Float64}(undef, N) - @test @gflops(my_axpy!(a, x, y)) == N - @test @gflops(my_axpy!(π, $(rand(N)), y)) == N + @test @gflops(my_axpy!($a, $x, $y)) == N + @test @gflops(my_axpy!($π, $(rand(N)), $y)) == N end let N = 100 m = rand(N, N) v = rand(N) - @test @gflops(my_prod(m, v)) == N*N + @test @gflops(my_prod($m, $v)) == N*N end end end