Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. # 0.6 Approach
  2. using BenchmarkTools
  3. using NullableArrays
  4.  
  5. n = 10_000_000
  6.  
  7. x = rand(n)
  8. y = NullableArray{Float64}(n)
  9. for i in 1:n
  10. if !iseven(i)
  11. y[i] = x[i]
  12. end
  13. end
  14.  
  15. sum(x)
  16. sum(y)
  17.  
  18. @benchmark sum($x)
  19. @benchmark sum($y)
  20.  
  21. # 0.7 Approach
  22. using BenchmarkTools
  23.  
  24. n = 10_000_000
  25.  
  26. x = rand(n)
  27. y = [ifelse(iseven(i), missing, x[i]) for i in 1:n]
  28.  
  29. sum(x)
  30. sum(y)
  31.  
  32. @benchmark sum($x)
  33. @benchmark sum($y)
Add Comment
Please, Sign In to add comment