Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using BenchmarkTools, Plots
  2.  
  3.  
  4. function bench_dot(N :: Int)
  5. T1 = zeros(N, 3)
  6. T2 = zeros(N, 3)
  7. T3 = zeros(N, 3)
  8. for i = 1:N
  9. n = 2^i
  10. println("Running for $n")
  11. x = rand(n)
  12. y = rand(n)
  13. t1 = @benchmark BLAS.dot($n, $x, 1, $y, 1)
  14. t2 = @benchmark BLAS.dot($x, $y)
  15. t3 = @benchmark dot($x,$y)
  16. t1 = t1.times
  17. t2 = t2.times
  18. t3 = t3.times
  19. T1[i,:] = [minimum(t1), mean(t1), maximum(t1)]
  20. T2[i,:] = [minimum(t2), mean(t2), maximum(t2)]
  21. T3[i,:] = [minimum(t3), mean(t3), maximum(t3)]
  22. end
  23. return T1, T2, T3
  24. end
  25.  
  26.  
  27. function bench_norm(N :: Int)
  28. T1 = zeros(N, 3)
  29. T2 = zeros(N, 3)
  30. T3 = zeros(N, 3)
  31. for i = 1:N
  32. n = 2^i
  33. println("Running for $n")
  34. x = rand(n)
  35. t1 = @benchmark BLAS.nrm2($n, $x, 1)
  36. t2 = @benchmark BLAS.nrm2($x)
  37. t3 = @benchmark norm($x)
  38. t1 = t1.times
  39. t2 = t2.times
  40. t3 = t3.times
  41. T1[i,:] = [minimum(t1), mean(t1), maximum(t1)]
  42. T2[i,:] = [minimum(t2), mean(t2), maximum(t2)]
  43. T3[i,:] = [minimum(t3), mean(t3), maximum(t3)]
  44. end
  45. return T1, T2, T3
  46. end
  47.  
  48.  
  49. function plotbench(T1, T2, T3, name1, name2, name3)
  50. N = size(T1, 1)
  51. t = 2.^(1:N)
  52. plot(xaxis = :log, yaxis=:log, reuse=false)
  53. plot!(t, T1[:,1], color=:red, l=:dash, lab="$name1 min")
  54. plot!(t, T1[:,2], color=:red, l=:solid, lab="$name1 mean")
  55. plot!(t, T1[:,3], color=:red, l=:dot, lab="$name1 max")
  56. plot!(t, T2[:,1], color=:blue, l=:dash, lab="$name2 min")
  57. plot!(t, T2[:,2], color=:blue, l=:solid, lab="$name2 mean")
  58. plot!(t, T2[:,3], color=:blue, l=:dot, lab="$name2 max")
  59. plot!(t, T3[:,1], color=:green, l=:dash, lab="$name3 min")
  60. plot!(t, T3[:,2], color=:green, l=:solid, lab="$name3 mean")
  61. plot!(t, T3[:,3], color=:green, l=:dot, lab="$name3 max")
  62. title!("$name1 vs $name2 vs $name3")
  63. xlabel!("Dimension")
  64. ylabel!("Time")
  65. png("$(name1)_vs_$(name2)_vs_$(name3)")
  66.  
  67. plot(t, T2[:,2]./T1[:,2], xaxis=:log, lab="$name2/$name1", reuse=false)
  68. plot!(t, T3[:,2]./T1[:,2], xaxis=:log, lab="$name3/$name1")
  69. title!("How much better is $name1?")
  70. xlabel!("Dimension")
  71. png("$(name1)_$(name2)_$(name3)_ratio")
  72. end
  73.  
  74. T1, T2, T3 = bench_dot(10)
  75. plotbench(T1, T2, T3, "BLAS.dot", "BLAS.dot (simple)", "dot")
  76. T1, T2, T3 = bench_norm(10)
  77. plotbench(T1, T2, T3, "BLAS.nrm2", "BLAS.nrm2 (simple)", "norm")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement