-
Notifications
You must be signed in to change notification settings - Fork 100
/
benchmarks.jl
37 lines (29 loc) · 1.32 KB
/
benchmarks.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using BenchmarkTools
# Define a parent BenchmarkGroup to contain our suite
const suite = BenchmarkGroup()
# Add some child groups to our benchmark suite.
suite["string"] = BenchmarkGroup(["unicode"])
suite["trig"] = BenchmarkGroup(["math", "triangles"])
suite["dot"] = BenchmarkGroup(["broadcast", "elementwise"])
# This string will be the same every time because we're seeding the RNG
teststr = join(rand(MersenneTwister(1), 'a':'d', 10^4))
# Add some benchmarks to the "string" group
suite["string"]["replace"] = @benchmarkable replace($teststr, "a", "b") seconds = Float64(π)
suite["string"]["join"] = @benchmarkable join($teststr, $teststr) samples = 42
# Add some benchmarks to the "trig"/"dot" group
for f in (sin, cos, tan)
for x in (0.0, pi)
suite["trig"][string(f), x] = @benchmarkable $(f)($x)
suite["dot"][string(f), x] = @benchmarkable $(f).([$x, $x, $x])
end
end
# If a cache of tuned parameters already exists, use it, otherwise, tune and cache
# the benchmark parameters. Reusing cached parameters is faster and more reliable
# than re-tuning `suite` every time the file is included.
paramspath = joinpath(dirname(@__FILE__), "params.json")
if isfile(paramspath)
loadparams!(suite, BenchmarkTools.load(paramspath)[1], :evals)
else
tune!(suite)
BenchmarkTools.save(paramspath, params(suite))
end