|
| 1 | +using BenchmarkTools |
| 2 | +using FillArrays |
| 3 | +using LinearAlgebra: triu, tril |
| 4 | + |
| 5 | +# Subtract the overhead from benchmark times |
| 6 | +BenchmarkTools.DEFAULT_PARAMETERS.overhead = BenchmarkTools.estimate_overhead() |
| 7 | + |
| 8 | +const SUITE = BenchmarkGroup() |
| 9 | + |
| 10 | +### |
| 11 | +### Eye |
| 12 | +### |
| 13 | + |
| 14 | +g = addgroup!(SUITE, "Eye", []) |
| 15 | + |
| 16 | +eye1float = Eye{Float64}(1) |
| 17 | +eye10float = Eye{Float64}(10) |
| 18 | +eye1000float = Eye{Float64}(1000) |
| 19 | +eye10int = Eye{Int}(10) |
| 20 | +eye1000int = Eye{Int}(1000) |
| 21 | + |
| 22 | +r1 = addgroup!(g, "reduction", []) |
| 23 | +r2 = addgroup!(g, "properties", ["properties"]) |
| 24 | +r3 = addgroup!(g, "any/all", []) |
| 25 | +r4 = addgroup!(g, "iterate", []) |
| 26 | +r5 = addgroup!(g, "identities", []) |
| 27 | + |
| 28 | +dimstring(a) = string("n=", size(a, 1)) |
| 29 | +fulldimstring(a) = string("size=", size(a)) |
| 30 | +funop(fun, op) = string(fun,"(", op, ", a)") |
| 31 | + |
| 32 | +for a in (eye10float, eye1000float, eye10int, eye1000int) |
| 33 | + for fun in (sum,) |
| 34 | + r1[string(fun), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($a) |
| 35 | + end |
| 36 | + for fun in (isone, iszero) |
| 37 | + r2[string(fun), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($a) |
| 38 | + end |
| 39 | + for (fun, op) in ((any, isone), (all, isone)) |
| 40 | + r3[funop(fun, op), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($op, $a) |
| 41 | + end |
| 42 | + for fun in (collect,) |
| 43 | + r4[string(fun), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($a) |
| 44 | + end |
| 45 | + for fun in (permutedims, triu, tril, inv) |
| 46 | + r5[string(fun), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($a) |
| 47 | + end |
| 48 | +end |
| 49 | + |
| 50 | +for a in (eye1float,) |
| 51 | + for (fun, op) in ((any, isone), (all, isone)) |
| 52 | + r3[funop(fun, op), string(eltype(a)), dimstring(a)] = @benchmarkable $fun($op, $a) |
| 53 | + end |
| 54 | +end |
| 55 | + |
| 56 | +### |
| 57 | +### Zeros |
| 58 | +### |
| 59 | + |
| 60 | +g1 = addgroup!(SUITE, "Zeros", []) |
| 61 | + |
| 62 | +zeros10 = Zeros(10) |
| 63 | +zeros10x10 = Zeros(10, 10) |
| 64 | + |
| 65 | +z1 = addgroup!(g1, "properties", ["properties"]) |
| 66 | + |
| 67 | +for a in (zeros10, zeros10x10) |
| 68 | + for fun in (iszero, ) |
| 69 | + z1[string(fun), string(eltype(a)), fulldimstring(a)] = @benchmarkable $fun($a) |
| 70 | + end |
| 71 | +end |
| 72 | + |
| 73 | +# If a cache of tuned parameters already exists, use it, otherwise, tune and cache |
| 74 | +# the benchmark parameters. Reusing cached parameters is faster and more reliable |
| 75 | +# than re-tuning `SUITE` every time the file is included. |
| 76 | +paramspath = joinpath(dirname(@__FILE__), "params.json") |
| 77 | + |
| 78 | +if isfile(paramspath) |
| 79 | + loadparams!(SUITE, BenchmarkTools.load(paramspath)[1], :evals); |
| 80 | +else |
| 81 | + tune!(SUITE) |
| 82 | + BenchmarkTools.save(paramspath, params(SUITE)); |
| 83 | +end |
| 84 | + |
| 85 | +result = run(SUITE, verbose = true) |
0 commit comments