-
Notifications
You must be signed in to change notification settings - Fork 39
/
bench-datatype.jl
92 lines (80 loc) · 2.37 KB
/
bench-datatype.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module BenchDataType
using BenchmarkTools
using Statistics
using Gadfly
using MLStyle
using DataFrames
import Match
import Rematch
using ..ArbitrarySampler
using ..Utils
@data NormalData begin
Normal1(a::Int, b::Int, c::Any)
Normal2(a::Int)
end
@data GenericData{A} begin
Generic1(a::A, b::Int)
Generic2(A)
end
mod′(n) = x -> mod(x, n)
specs = [
:s1 => @spec(Normal1(::Int, ::Int, ::Real || ::Complex || _)),
:s2 => @spec(Normal1(::Int, ::Int, Normal2(1 || ::Int))),
:s3 => @spec(Generic1(3 || _, 4 || ::Int)),
:s4 => @spec(Generic2((1 || _, 2 || _))),
:s5 => @spec(Generic1(::String || _, 0) || Generic2(::String || _)),
:s6 => @spec(
Generic1(_, ::Int) || Generic2(_) || Normal2(::Int) || Normal1(::Int, ::Int, _)
),
:_ => @spec(_),
]
implementations = [
:MLStyle => (@λ begin
Normal1(c = ::Number) -> 1
Normal1(c = Normal2(1)) -> 2
Generic1(a = 3, b = 3) -> 3
Generic2((1, 2)) -> 4
::GenericData{String} -> 5
_ -> 0
end),
:Rematch => function (x)
Rematch.@match x begin
Normal1(_, _, _::Number) => 1
Normal1(_, _, Normal2(1)) => 2
Generic1(3, 3) => 3
Generic2((1, 2)) => 4
_::GenericData{String} => 5
_ => 0
end
end,
Symbol("Match.jl") => function (x)
Match.@match x begin
Normal1(_, _, _::Number) => 1
Normal1(_, _, Normal2(1)) => 2
Generic1(3, 3) => 3
Generic2((1, 2)) => 4
_::GenericData{String} => 5
_ => 0
end
end,
]
records = NamedTuple{(:time_mean, :implementation, :case)}[]
for (spec_id, spec) in specs
# group_key = string(spec_id)
# suite[group_key] = BenchmarkGroup()
for (impl_id, impl_fn) in implementations
bench′ =
@benchmark $impl_fn(sample) setup = (sample = $generate($spec)) samples = 2000
time′ = mean(bench′.times)
@info :bench (spec_id, impl_id, time′)
push!(records, (time_mean = time′, implementation = impl_id, case = spec_id))
end
end
df = DataFrame(records)
@info df
report_meantime, df_time = report(df, Guide.title("Data Types"); benchfield = :time_mean)
open("stats/bench-datatype.txt", "w") do f
write(f, string(df))
end
draw(SVG("stats/bench-datatype.svg", 14inch, 6inch), report_meantime)
end