Advertisement
dluciv

Untitled

Mar 31st, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.46 KB | None | 0 0
  1. function ttime(adim)
  2.   r1 = rand(adim, adim)
  3.   @time begin
  4.     summ = 0.0
  5.     for i in 1:adim
  6.       for j in 1:adim
  7.         summ += r1[i,j]
  8.       end
  9.     end
  10.     println(summ)
  11.   end
  12.  
  13.   @time begin
  14.     summ = 0.0
  15.     for j in 1:adim
  16.       for i in 1:adim
  17.         summ += r1[i,j]
  18.       end
  19.     end
  20.     println(summ)
  21.   end
  22. end
  23.  
  24. ttime(40) # to precompile
  25. ttime(16000) # to give it a load
  26.  
  27. # Row-major order really is about 10-12 times slower in Julia
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement