Created
January 22, 2017 18:22
-
-
Save dpo/272c500b0e0a8557682378b6924aeb48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools, Plots | |
function bench_dot(N :: Int) | |
T1 = zeros(N, 3) | |
T2 = zeros(N, 3) | |
T3 = zeros(N, 3) | |
for i = 1:N | |
n = 2^i | |
println("Running for $n") | |
x = rand(n) | |
y = rand(n) | |
t1 = @benchmark BLAS.dot($n, $x, 1, $y, 1) | |
t2 = @benchmark BLAS.dot($x, $y) | |
t3 = @benchmark dot($x,$y) | |
t1 = t1.times | |
t2 = t2.times | |
t3 = t3.times | |
T1[i,:] = [minimum(t1), mean(t1), maximum(t1)] | |
T2[i,:] = [minimum(t2), mean(t2), maximum(t2)] | |
T3[i,:] = [minimum(t3), mean(t3), maximum(t3)] | |
end | |
return T1, T2, T3 | |
end | |
function bench_norm(N :: Int) | |
T1 = zeros(N, 3) | |
T2 = zeros(N, 3) | |
T3 = zeros(N, 3) | |
for i = 1:N | |
n = 2^i | |
println("Running for $n") | |
x = rand(n) | |
t1 = @benchmark BLAS.nrm2($n, $x, 1) | |
t2 = @benchmark BLAS.nrm2($x) | |
t3 = @benchmark norm($x) | |
t1 = t1.times | |
t2 = t2.times | |
t3 = t3.times | |
T1[i,:] = [minimum(t1), mean(t1), maximum(t1)] | |
T2[i,:] = [minimum(t2), mean(t2), maximum(t2)] | |
T3[i,:] = [minimum(t3), mean(t3), maximum(t3)] | |
end | |
return T1, T2, T3 | |
end | |
function plotbench(T1, T2, T3, name1, name2, name3) | |
N = size(T1, 1) | |
t = 2.^(1:N) | |
plot(xaxis = :log, yaxis=:log, reuse=false) | |
plot!(t, T1[:,1], color=:red, l=:dash, lab="$name1 min") | |
plot!(t, T1[:,2], color=:red, l=:solid, lab="$name1 mean") | |
plot!(t, T1[:,3], color=:red, l=:dot, lab="$name1 max") | |
plot!(t, T2[:,1], color=:blue, l=:dash, lab="$name2 min") | |
plot!(t, T2[:,2], color=:blue, l=:solid, lab="$name2 mean") | |
plot!(t, T2[:,3], color=:blue, l=:dot, lab="$name2 max") | |
plot!(t, T3[:,1], color=:green, l=:dash, lab="$name3 min") | |
plot!(t, T3[:,2], color=:green, l=:solid, lab="$name3 mean") | |
plot!(t, T3[:,3], color=:green, l=:dot, lab="$name3 max") | |
title!("$name1 vs $name2 vs $name3") | |
xlabel!("Dimension") | |
ylabel!("Time") | |
png("$(name1)_vs_$(name2)_vs_$(name3)") | |
plot(t, T2[:,2]./T1[:,2], xaxis=:log, lab="$name2/$name1", reuse=false) | |
plot!(t, T3[:,2]./T1[:,2], xaxis=:log, lab="$name3/$name1") | |
title!("How much better is $name1?") | |
xlabel!("Dimension") | |
png("$(name1)_$(name2)_$(name3)_ratio") | |
end | |
T1, T2, T3 = bench_dot(10) | |
plotbench(T1, T2, T3, "BLAS.dot", "BLAS.dot (simple)", "dot") | |
T1, T2, T3 = bench_norm(10) | |
plotbench(T1, T2, T3, "BLAS.nrm2", "BLAS.nrm2 (simple)", "norm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment