From ff54fd6713cc4af17ee4602783bbeaeed8131884 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Tue, 1 Oct 2019 11:46:51 -0500 Subject: [PATCH 1/5] rebasing @localbtime and friends from LocalScopeBenchmarks.jl --- Manifest.toml | 135 +++++++++++++++++++++++++++++ Project.toml | 2 + src/BenchmarkTools.jl | 9 +- src/execution.jl | 107 +++++++++++++++++++++++ test/LocalScopeBenchmarkTests.jl | 143 +++++++++++++++++++++++++++++++ test/runtests.jl | 4 + 6 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 Manifest.toml create mode 100644 test/LocalScopeBenchmarkTests.jl diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 00000000..6f2c80ef --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,135 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[CSTParser]] +deps = ["Tokenize"] +git-tree-sha1 = "c69698c3d4a7255bc1b4bc2afc09f59db910243b" +uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f" +version = "0.6.2" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "2.1.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "517ce30aa57cdfae1ab444a7c0aef8bb86345bc2" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.17.1" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"] +git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.1.0" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.7" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[Tokenize]] +git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf" +uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624" +version = "0.5.6" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/Project.toml b/Project.toml index b7464b31..d1f1aeb4 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,8 @@ version = "0.4.3" [deps] JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/BenchmarkTools.jl b/src/BenchmarkTools.jl index 619e493d..e3f964a1 100644 --- a/src/BenchmarkTools.jl +++ b/src/BenchmarkTools.jl @@ -5,9 +5,11 @@ using Base.Iterators using Statistics using Printf +using MacroTools: MacroTools, prewalk, postwalk, @capture +using OrderedCollections: OrderedDict -const BENCHMARKTOOLS_VERSION = v"0.4.3" +const BENCHMARKTOOLS_VERSION = v"0.4.4" ############## # Parameters # @@ -63,7 +65,10 @@ export tune!, @benchmark, @benchmarkable, @belapsed, - @btime + @btime, + @localbenchmark, + @localbelapsed, + @localbtime ################# # Serialization # diff --git a/src/execution.jl b/src/execution.jl index 9d4f7058..fa878dbe 100644 --- a/src/execution.jl +++ b/src/execution.jl @@ -400,3 +400,110 @@ macro btime(args...) $result end) end + +#################### +# Local Benchmarks # +#################### + +# Credit to Robin Deits @rdeits for introducing this code in LocalScopeBenchmarks.jl + +function collect_symbols(expr) + assignments = OrderedDict{Symbol, Expr}() + prewalk(expr) do x + if x isa Symbol + assignments[x] = Expr(:$, x) + return nothing + elseif x isa Expr && x.head == :$ + # Don't recurse inside $() interpolations, + # since those will already be interpolated + return nothing + else + return x + end + end + assignments +end + +function parse_setup(setup::Expr) + assignments = OrderedDict() + postwalk(setup) do x + if @capture(x, a_ = b_) + assignments[a] = b + end + x + end + assignments +end + +function lower_setup(assignments::AbstractDict) + Expr(:block, [Expr(:(=), k, v) for (k, v) in assignments]...) +end + +function parse_params(kwargs) + params_dict = OrderedDict((@assert x.head == :kw; x.args[1] => x.args[2]) for x in kwargs) +end + +function lower_params(params::AbstractDict) + [Expr(:kw, k, v) for (k, v) in params] +end + +function interpolate_locals_into_setup(args...) + core, kwargs = BenchmarkTools.prunekwargs(args...) + params = parse_params(kwargs) + setup_assignments = parse_setup(get(() -> Expr(:block), params, :setup)) + local_assignments = collect_symbols(core) + setup = merge(local_assignments, setup_assignments) + params[:setup] = lower_setup(setup) + core, lower_params(params) +end + + +macro localbenchmark(args...) + core, params = interpolate_locals_into_setup(args...) + quote + BenchmarkTools.@benchmark($(core), $(params...)) + end +end + +""" + @localbtime expression [other parameters...] + +Similar to the `@time` macro included with Julia, +this executes an expression, printing the time +it took to execute and the memory allocated before +returning the value of the expression. + +Unlike `@time`, it uses the `@benchmark` +macro, and accepts all of the same additional +parameters as `@benchmark`. The printed time +is the *minimum* elapsed time measured during the benchmark. + +This macro allows you to use local scoping with the expression called. +Please see the tests for further examples. +""" +macro localbtime(args...) + core, params = interpolate_locals_into_setup(args...) + quote + BenchmarkTools.@btime($(core), $(params...)) + end +end + +""" + @localbelapsed expression [other parameters...] + +Similar to the `@elapsed` macro included with Julia, +this returns the elapsed time (in seconds) to +execute a given expression. It uses the `@benchmark` +macro, however, and accepts all of the same additional +parameters as `@benchmark`. The returned time +is the *minimum* elapsed time measured during the benchmark. + +This macro allows you to use local scoping within the expression called. +Please see the tests for further examples. +""" +macro localbelapsed(args...) + core, params = interpolate_locals_into_setup(args...) + quote + BenchmarkTools.@belapsed($(core), $(params...)) + end +end diff --git a/test/LocalScopeBenchmarkTests.jl b/test/LocalScopeBenchmarkTests.jl new file mode 100644 index 00000000..b2fd9a40 --- /dev/null +++ b/test/LocalScopeBenchmarkTests.jl @@ -0,0 +1,143 @@ +using Test +using BenchmarkTools +using Statistics + +function judge_loosely(t1, t2) + judge(ratio(median(t1), median(t2)), time_tolerance=0.2) +end + +global_x = 1.0 + +@testset "LocalScopeBenchmarks" begin + @testset "Basic benchmarks" begin + x = 1.0 + t1 = @benchmark(sin($x)) + t2 = @localbenchmark(sin(x)) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + + t1 = @benchmark($sin($x)) + t2 = @localbenchmark(sin(x)) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + + f = sin + x = 1.0 + t1 = @benchmark($f($x)) + t2 = @localbenchmark(f(x)) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + + @testset "Benchmarks with setup" begin + @testset "Single setup" begin + t1 = @benchmark sin(x) setup=(x = 2.0) + t2 = @localbenchmark sin(x) setup=(x = 2.0) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + + @testset "Multiple setups" begin + t1 = @benchmark atan(x, y) setup=(x = 2.0; y = 1.5) + t2 = @localbenchmark atan(x, y) setup=(x = 2.0; y = 1.5) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + + @testset "Setups override local vars" begin + x = 1.0 + @localbenchmark (@assert x == 2.0) setup=(x = 2.0) evals=1 + end + + @testset "Mixed setup and local vars" begin + x = 1.0 + t1 = @benchmark atan($x, y) setup=(y = 2.0) + t2 = @localbenchmark atan(x, y) setup=(y = 2.0) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + @testset "Simple generators and comprehensions" begin + + x = [i for i in 1:1000] + t1 = @benchmark sum($x) + t2 = @localbenchmark sum(x) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + + x = (i for i in 1:1000) + t1 = @benchmark sum($x) + t2 = @localbenchmark sum(x) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + @testset "Gens, comps, override local vars" begin + x = [1.0, 1.0, 1.0] + y = [2.0, 2.0, 2.0] + t1 = @benchmark atan.($x, y) setup=(y = [2.0 for i in 1:3]) + t2 = @localbenchmark atan.(x, y) setup=(y = [2.0 for i in 1:3]) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + end + @testset "Additional kwargs" begin + @testset "evals kwarg" begin + x = 1.0 + t1 = @benchmark sin($x) evals=5 + t2 = @localbenchmark sin(x) evals=5 + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + + @testset "evals and setup kwargs" begin + t1 = @benchmark sin(x) setup=(x = 2.0) evals=5 + t2 = @localbenchmark sin(x) setup=(x = 2.0) evals=5 + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + @testset "kwargs, evals and gens and comprehension filters" begin + f(x) = x # define some generators based on local scope + i = π + N = 3 + x = [1, 3] + y = [1, 3] + t1 = @benchmark atan.($x, y) setup=(y = [$f(i) for i in 1:$N if $f(i) % 3 != 0]) evals=100 + t2 = @localbenchmark atan.(x, y) setup=(y = [f(i) for i in 1:N if f(i) % 2 != 0]) evals=100 + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end + end + + @testset "Test that local benchmarks are faster than globals" begin + t1 = @benchmark sin(global_x) evals=5 # note the lack of $ + t2 = @localbenchmark sin(global_x) evals=5 + j = judge_loosely(t1, t2) + @show j + @test isregression(j) + end + + @testset "Other macros" begin + x = 1.0 + @localbtime sin(x) + @localbelapsed sin(x) + end + + @testset "Interpolated values" begin + t1 = @benchmark sum($(rand(1000))) + t2 = @localbenchmark sum($(rand(1000))) + j = judge_loosely(t1, t2) + @show j + @test isinvariant(j) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index e7259482..9a1bd7ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,3 +17,7 @@ println("done (took ", took_seconds, " seconds)") print("Testing serialization...") took_seconds = @elapsed include("SerializationTests.jl") println("done (took ", took_seconds, " seconds)") + +print("Testing LocalScopeBenchmarks") +took_seconds = @elapsed include("LocalScopeBenchmarkTests.jl") +println("done (took ", took_seconds, " seconds)") From 227c36d49c5b430981959f35e8838e87e3df00be Mon Sep 17 00:00:00 2001 From: miguelraz Date: Tue, 15 Oct 2019 21:53:15 -0500 Subject: [PATCH 2/5] Fixed tests for localbenchmarks, change median to mean time, added eval cycles to increase reliability --- src/execution.jl | 2 +- test/LocalScopeBenchmarkTests.jl | 51 +++++++++++++------------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/execution.jl b/src/execution.jl index fa878dbe..34fab648 100644 --- a/src/execution.jl +++ b/src/execution.jl @@ -499,7 +499,7 @@ parameters as `@benchmark`. The returned time is the *minimum* elapsed time measured during the benchmark. This macro allows you to use local scoping within the expression called. -Please see the tests for further examples. +Please see the tests for further examples. """ macro localbelapsed(args...) core, params = interpolate_locals_into_setup(args...) diff --git a/test/LocalScopeBenchmarkTests.jl b/test/LocalScopeBenchmarkTests.jl index b2fd9a40..5ebb7971 100644 --- a/test/LocalScopeBenchmarkTests.jl +++ b/test/LocalScopeBenchmarkTests.jl @@ -3,7 +3,7 @@ using BenchmarkTools using Statistics function judge_loosely(t1, t2) - judge(ratio(median(t1), median(t2)), time_tolerance=0.2) + judge(ratio(mean(t1), mean(t2)), time_tolerance=0.2) end global_x = 1.0 @@ -11,33 +11,31 @@ global_x = 1.0 @testset "LocalScopeBenchmarks" begin @testset "Basic benchmarks" begin x = 1.0 - t1 = @benchmark(sin($x)) - t2 = @localbenchmark(sin(x)) + evals = 500 + t1 = @benchmark($sin($x), evals=500) + t2 = @localbenchmark(sin(x), evals=500) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) - t1 = @benchmark($sin($x)) - t2 = @localbenchmark(sin(x)) + t1 = @benchmark($sin($x), evals=500) + t2 = @localbenchmark(sin(x), evals=500) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) f = sin x = 1.0 - t1 = @benchmark($f($x)) - t2 = @localbenchmark(f(x)) + t1 = @benchmark($f($x), evals=500) + t2 = @localbenchmark(f(x), evals=500) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "Benchmarks with setup" begin @testset "Single setup" begin + x =1.0 t1 = @benchmark sin(x) setup=(x = 2.0) t2 = @localbenchmark sin(x) setup=(x = 2.0) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @@ -45,13 +43,15 @@ global_x = 1.0 t1 = @benchmark atan(x, y) setup=(x = 2.0; y = 1.5) t2 = @localbenchmark atan(x, y) setup=(x = 2.0; y = 1.5) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "Setups override local vars" begin x = 1.0 - @localbenchmark (@assert x == 2.0) setup=(x = 2.0) evals=1 + t1 = @benchmark (@assert x == 2.0) setup=(x = 2.0) evals = 500 + t2 = @localbenchmark (@assert x == 2.0) setup=(x = 2.0) evals=500 + j = judge_loosely(t1,t2) + @test isinvariant(j) end @testset "Mixed setup and local vars" begin @@ -59,23 +59,19 @@ global_x = 1.0 t1 = @benchmark atan($x, y) setup=(y = 2.0) t2 = @localbenchmark atan(x, y) setup=(y = 2.0) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "Simple generators and comprehensions" begin - x = [i for i in 1:1000] t1 = @benchmark sum($x) t2 = @localbenchmark sum(x) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) x = (i for i in 1:1000) t1 = @benchmark sum($x) t2 = @localbenchmark sum(x) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "Gens, comps, override local vars" begin @@ -84,7 +80,6 @@ global_x = 1.0 t1 = @benchmark atan.($x, y) setup=(y = [2.0 for i in 1:3]) t2 = @localbenchmark atan.(x, y) setup=(y = [2.0 for i in 1:3]) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end end @@ -94,15 +89,14 @@ global_x = 1.0 t1 = @benchmark sin($x) evals=5 t2 = @localbenchmark sin(x) evals=5 j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "evals and setup kwargs" begin - t1 = @benchmark sin(x) setup=(x = 2.0) evals=5 - t2 = @localbenchmark sin(x) setup=(x = 2.0) evals=5 + x = 1.0 + t1 = @benchmark sin($x) setup=(x = 2.0) evals=500 + t2 = @localbenchmark sin(x) setup=(x = 2.0) evals=500 j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end @testset "kwargs, evals and gens and comprehension filters" begin @@ -110,11 +104,10 @@ global_x = 1.0 i = π N = 3 x = [1, 3] - y = [1, 3] - t1 = @benchmark atan.($x, y) setup=(y = [$f(i) for i in 1:$N if $f(i) % 3 != 0]) evals=100 - t2 = @localbenchmark atan.(x, y) setup=(y = [f(i) for i in 1:N if f(i) % 2 != 0]) evals=100 + y = [f(i) for i = 1:N if f(i) % 2 != 0] + t1 = @benchmark atan.($x, y) setup=(y = [$f(i) for i in 1:$N if $f(i) % 2 != 0]) evals=100 + t2 = @localbenchmark atan.(x, y) setup=(x = [1, 3]) evals=100 j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end end @@ -123,21 +116,19 @@ global_x = 1.0 t1 = @benchmark sin(global_x) evals=5 # note the lack of $ t2 = @localbenchmark sin(global_x) evals=5 j = judge_loosely(t1, t2) - @show j @test isregression(j) end @testset "Other macros" begin x = 1.0 - @localbtime sin(x) - @localbelapsed sin(x) + t1 = @localbtime sin($x) + t2 = @localbelapsed sin(x) end @testset "Interpolated values" begin t1 = @benchmark sum($(rand(1000))) t2 = @localbenchmark sum($(rand(1000))) j = judge_loosely(t1, t2) - @show j @test isinvariant(j) end end From 2f2394150c476877497ca82a9b601da0ab5cb8e7 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Tue, 15 Oct 2019 21:57:11 -0500 Subject: [PATCH 3/5] Delete spurious Manifest --- Manifest.toml | 135 -------------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index 6f2c80ef..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,135 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[CSTParser]] -deps = ["Tokenize"] -git-tree-sha1 = "c69698c3d4a7255bc1b4bc2afc09f59db910243b" -uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f" -version = "0.6.2" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "2.1.0" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "517ce30aa57cdfae1ab444a7c0aef8bb86345bc2" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.1" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.0" - -[[LibGit2]] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[MacroTools]] -deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"] -git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.1" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.1.0" - -[[Parsers]] -deps = ["Dates", "Test"] -git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.7" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[Tokenize]] -git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf" -uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624" -version = "0.5.6" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" From 9d7a917752fb3cf7dd29c7d80ecd49aeea6b0269 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Tue, 15 Oct 2019 23:14:36 -0500 Subject: [PATCH 4/5] Add test for identical generated code --- test/LocalScopeBenchmarkTests.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/LocalScopeBenchmarkTests.jl b/test/LocalScopeBenchmarkTests.jl index 5ebb7971..ed120235 100644 --- a/test/LocalScopeBenchmarkTests.jl +++ b/test/LocalScopeBenchmarkTests.jl @@ -30,6 +30,12 @@ global_x = 1.0 @test isinvariant(j) end + @testset "Generated code is identical" begin + x = 1.0 + ex1 = Meta.@lower(@benchmark($sin($x), evals=500)) + ex2 = Meta.@lower(@localbenchmark(sin(x), evals=500)) + end + @testset "Benchmarks with setup" begin @testset "Single setup" begin x =1.0 From 875be87a017cc6912b568224e5aece56976eb66e Mon Sep 17 00:00:00 2001 From: miguelraz Date: Tue, 15 Oct 2019 23:18:03 -0500 Subject: [PATCH 5/5] Add warning about copy pasting test into REPL --- test/LocalScopeBenchmarkTests.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/LocalScopeBenchmarkTests.jl b/test/LocalScopeBenchmarkTests.jl index ed120235..5e3e60bf 100644 --- a/test/LocalScopeBenchmarkTests.jl +++ b/test/LocalScopeBenchmarkTests.jl @@ -30,11 +30,13 @@ global_x = 1.0 @test isinvariant(j) end - @testset "Generated code is identical" begin - x = 1.0 - ex1 = Meta.@lower(@benchmark($sin($x), evals=500)) - ex2 = Meta.@lower(@localbenchmark(sin(x), evals=500)) - end +# This test fails to run if copy/pasted into the REPL due to differing LineNumbers where vars get +# pulled from. + @testset "Generated code is identical" begin + x = 1.0 + ex1 = Meta.@lower(@benchmark($sin($x), evals=500)) + ex2 = Meta.@lower(@localbenchmark(sin(x), evals=500)) + end @testset "Benchmarks with setup" begin @testset "Single setup" begin