Skip to content

Commit 54e4cae

Browse files
committed
Add main script: benchmark/runbench.jl
Use custom branch of `PkgBenchmark.jl` to support post-processing, which we need.
1 parent 75639c6 commit 54e4cae

File tree

4 files changed

+167
-10
lines changed

4 files changed

+167
-10
lines changed

benchmark/Manifest.toml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[[Base64]]
2+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
3+
4+
[[BenchmarkTools]]
5+
deps = ["JSON", "Printf", "Statistics", "Test"]
6+
git-tree-sha1 = "e686f1754227e4748259f400839b83a1e8773e02"
7+
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
8+
version = "0.4.1"
9+
10+
[[Dates]]
11+
deps = ["Printf"]
12+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
13+
14+
[[Distributed]]
15+
deps = ["Random", "Serialization", "Sockets"]
16+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
17+
18+
[[InteractiveUtils]]
19+
deps = ["Markdown"]
20+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
21+
22+
[[JSON]]
23+
deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"]
24+
git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa"
25+
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
26+
version = "0.20.0"
27+
28+
[[LibGit2]]
29+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
30+
31+
[[Libdl]]
32+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
33+
34+
[[LinearAlgebra]]
35+
deps = ["Libdl"]
36+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
37+
38+
[[Logging]]
39+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
40+
41+
[[Markdown]]
42+
deps = ["Base64"]
43+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
44+
45+
[[Mmap]]
46+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
47+
48+
[[Pkg]]
49+
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
50+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
51+
52+
[[PkgBenchmark]]
53+
deps = ["BenchmarkTools", "Dates", "InteractiveUtils", "JSON", "LibGit2", "Pkg", "Printf", "ProgressMeter", "Random", "Test"]
54+
git-tree-sha1 = "d15f09c1e4a8c1075db6025fed97b8a852d5738e"
55+
repo-rev = "post-processing"
56+
repo-url = "https://github.com/NHDaly/PkgBenchmark.jl"
57+
uuid = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
58+
version = "0.2.0+"
59+
60+
[[Printf]]
61+
deps = ["Unicode"]
62+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
63+
64+
[[ProgressMeter]]
65+
deps = ["Distributed", "Printf", "Random", "Test"]
66+
git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787"
67+
uuid = "92933f4c-e287-5a05-a399-4b506db050ca"
68+
version = "0.9.0"
69+
70+
[[REPL]]
71+
deps = ["InteractiveUtils", "Markdown", "Sockets"]
72+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
73+
74+
[[Random]]
75+
deps = ["Serialization"]
76+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
77+
78+
[[SHA]]
79+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
80+
81+
[[Serialization]]
82+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
83+
84+
[[Sockets]]
85+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
86+
87+
[[SparseArrays]]
88+
deps = ["LinearAlgebra", "Random"]
89+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
90+
91+
[[Statistics]]
92+
deps = ["LinearAlgebra", "SparseArrays"]
93+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
94+
95+
[[Test]]
96+
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
97+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
98+
99+
[[UUIDs]]
100+
deps = ["Random", "SHA"]
101+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
102+
103+
[[Unicode]]
104+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"

benchmark/benchmarks.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
# It compares fixed-decimal types against the builtin Int and Float types of various sizes.
88
# The output is written to a .csv file in the same directory as this file.
99

10+
# TODO: remove this file once BenchmarkTools has a built-in solution for diffing two
11+
# @benchmarkable runs
12+
using Pkg
13+
Pkg.activate(@__DIR__)
14+
1015
using FixedPointDecimals
1116
using Random
1217
using BenchmarkTools, Statistics
1318

14-
# # TODO: remove this file once BenchmarkTools has a built-in solution for diffing two
15-
# # @benchmarkable runs
16-
# include("subtract-benchmarks.jl")
17-
1819
# Define a parent BenchmarkGroup to contain our suite
1920
const SUITE = BenchmarkGroup()
21+
const N = parse(Int, get(ENV, "BENCH_NUM_ITERS", "1000"))
2022

2123
decimal_precision = 2
2224

@@ -78,7 +80,7 @@ end
7880
for op in allops
7981
SUITE[opname(op)] = BenchmarkGroup()
8082
for T in alltypes
81-
SUITE[opname(op)][type(T)] = BenchmarkGroup(["diff"])
83+
SUITE[opname(op)][type(T)] = BenchmarkGroup(["base", "bench"])
8284
end
8385
end
8486

@@ -88,7 +90,6 @@ for op in allops
8890
for T in alltypes
8991
print("$T ")
9092

91-
N = 1 # _000 #_000
9293
initial_value = zero(T)
9394
a = one(T)
9495

@@ -98,10 +99,8 @@ for op in allops
9899

99100
# Run the benchmark
100101
outbase = Ref(initial_value)
101-
bbase = @benchmarkable $fbase($outbase) evals=1 setup=($outbase[]=$initial_value)
102+
SUITE[opname(op)][type(T)]["base"] = @benchmarkable $fbase($outbase) evals=1 setup=($outbase[]=$initial_value)
102103
outbench = Ref(initial_value)
103-
bbench = @benchmarkable $fbench($outbench) evals=1 setup=($outbench[]=$initial_value)
104-
bdiff = bbench - bbase
105-
SUITE[opname(op)][type(T)]["diff"] = bdiff
104+
SUITE[opname(op)][type(T)]["bench"] = @benchmarkable $fbench($outbench) evals=1 setup=($outbench[]=$initial_value)
106105
end
107106
end

benchmark/runbench.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module FixedPointDecimals_RunBench
2+
3+
using Pkg
4+
5+
Pkg.activate(@__DIR__)
6+
using PkgBenchmark, BenchmarkTools, Statistics
7+
8+
const N = 1_000
9+
10+
import Base: -, /
11+
function -(a::BenchmarkTools.TrialEstimate, b::BenchmarkTools.TrialEstimate)
12+
ttol = max(params(a).time_tolerance, params(b).time_tolerance)
13+
mtol = max(params(a).memory_tolerance, params(b).memory_tolerance)
14+
p = BenchmarkTools.Parameters(params(a); time_tolerance = ttol, memory_tolerance = mtol)
15+
return BenchmarkTools.TrialEstimate(p, -(time(a), time(b)), -(gctime(a), gctime(b)),
16+
-(memory(a), memory(b)), -(allocs(a), allocs(b)))
17+
end
18+
function /(a::BenchmarkTools.TrialEstimate, b::Int)
19+
ttol = params(a).time_tolerance / b
20+
mtol = params(a).memory_tolerance / b
21+
p = BenchmarkTools.Parameters(params(a); time_tolerance = ttol, memory_tolerance = mtol)
22+
return BenchmarkTools.TrialEstimate(p, time(a)/b, gctime(a)/b,
23+
memory(a)/b, allocs(a)/b)
24+
end
25+
26+
function postprocess(results::BenchmarkGroup)
27+
global _results = deepcopy(results)
28+
for (op, op_group) in results.data
29+
op_results = op_group.data
30+
for (type, type_group) in op_results
31+
benchresults = type_group.data
32+
if op == "identity"
33+
# For :identity, bench and base are identical so we don't want to subtract.
34+
op_results[type] = median(benchresults["bench"]) / N
35+
else
36+
op_results[type] = median(benchresults["bench"])/N - median(benchresults["base"])/N
37+
end
38+
end
39+
end
40+
results
41+
end
42+
results = deepcopy(_results)
43+
((results)->(results["*"]["BigInt"]["bench"]=median(results["*"]["BigInt"]["bench"])/1000))(results)
44+
45+
bench_results = withenv("BENCH_NUM_ITERS"=>string(N)) do
46+
benchmarkpkg("FixedPointDecimals"; postprocess=postprocess)
47+
end
48+
49+
export_markdown("results.md", bench_results)
50+
51+
end

0 commit comments

Comments
 (0)