-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.jl
44 lines (36 loc) · 1.05 KB
/
bench.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
using BenchmarkTools, PyPlot
using Base.Math.@horner, ParPoly
bench(f::Function, X) = mapreduce(x -> reinterpret(Unsigned,x), |, f(x) for x in X)
X = randn(1_000_000)
nn = 5:25
time_h = Float64[]
time_hs = Float64[]
time_hss = Float64[]
for n in nn
println("running bench for order $n")
c = randn(Float64,n+1)
@gensym f1
@gensym f2
@gensym f3
@eval begin
$f1(x) = @horner x $(c...)
$f2(x) = @horner_split x $(c...)
$f3(x) = @horner_split_simd x $(c...)
end
@eval begin
$f1(2.); $f2($2.); $f3($2.) # precompile them
end
t_h = @benchmark bench($f1, $X)
t_hs = @benchmark bench($f2, $X)
t_hss = @benchmark bench($f3, $X)
push!(time_h, mean(t_h).time)
push!(time_hs, mean(t_hs).time)
push!(time_hss, mean(t_hss).time)
end
plot(nn, time_h*0.000001, label="@horner")
plot(nn, time_hs*0.000001, label="@horner_split")
plot(nn, time_hss*0.000001, label="@horner_split_simd")
legend(loc="upper left")
xlabel("polynomial order")
ylabel("time (ms)")
savefig("out.jpg")