Guest User

Untitled

a guest
Dec 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function test1()
  2. n = 1000000
  3. a = randn(n)
  4. b = randn(n)
  5. c = randn(n)
  6. for i=1:500
  7. result = sum(a + b + c)
  8. end
  9. end
  10.  
  11. function test2()
  12. n = 1000000
  13. a = randn(n)
  14. b = randn(n)
  15. c = randn(n)
  16. result = 0.0
  17. for i=1:500
  18. for j = 1:length(a)
  19. result += a[j] + b[j] + c[j]
  20. end
  21. end
  22. result
  23. end
  24.  
  25. @time test1() # elapsed time: 6.3725199699401855 seconds
  26.  
  27. @time test2() # elapsed time: 2.0483860969543457 seconds
Add Comment
Please, Sign In to add comment