Skip to content

Commit 46b1d5a

Browse files
authored
spice up the example code (#46)
* spicier example capable of showing kwargs and tag filtering * add compat warning to example
1 parent bfdd30e commit 46b1d5a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

benchmark/benchmarks.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
VERSION < v"0.5" && warn("This example uses dot broadcast syntax "*
2+
"and may not work on Julia versions lower"*
3+
" than v0.5!")
4+
15
using BenchmarkTools
26

37
# Define a parent BenchmarkGroup to contain our suite
48
const suite = BenchmarkGroup()
59

610
# Add some child groups to our benchmark suite.
711
suite["string"] = BenchmarkGroup(["unicode"])
8-
suite["trigonometry"] = BenchmarkGroup(["math", "triangles"])
12+
suite["trig"] = BenchmarkGroup(["math", "triangles"])
13+
suite["dot"] = BenchmarkGroup(["broadcast", "elementwise"])
914

1015
# This string will be the same every time because we're seeding the RNG
1116
teststr = join(rand(MersenneTwister(1), 'a':'d', 10^4))
1217

1318
# Add some benchmarks to the "utf8" group
14-
suite["string"]["replace"] = @benchmarkable replace($teststr, "a", "b")
15-
suite["string"]["join"] = @benchmarkable join($teststr, $teststr)
19+
suite["string"]["replace"] = @benchmarkable replace($teststr, "a", "b") seconds=Float64(π)
20+
suite["string"]["join"] = @benchmarkable join($teststr, $teststr) samples=42
1621

17-
# Add some benchmarks to the "trigonometry" group
22+
# Add some benchmarks to the "trig"/"dot" group
1823
for f in (sin, cos, tan)
1924
for x in (0.0, pi)
20-
suite["trigonometry"][string(f), x] = @benchmarkable $(f)($x)
25+
suite["trig"][string(f), x] = @benchmarkable $(f)($x)
26+
suite["dot"][string(f), x] = @benchmarkable $(f).([$x, $x, $x])
2127
end
2228
end
2329

@@ -27,7 +33,7 @@ end
2733
paramspath = joinpath(dirname(@__FILE__), "params.jld")
2834

2935
if isfile(paramspath)
30-
loadparams!(suite, BenchmarkTools.load(paramspath, "suite"), :evals, :samples);
36+
loadparams!(suite, BenchmarkTools.load(paramspath, "suite"), :evals);
3137
else
3238
tune!(suite)
3339
BenchmarkTools.save(paramspath, "suite", params(suite));

0 commit comments

Comments
 (0)