Skip to content

Instantly share code, notes, and snippets.

@johnmyleswhite
Created June 18, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmyleswhite/cd13a437a572159788820ad40bcf7e84 to your computer and use it in GitHub Desktop.
Save johnmyleswhite/cd13a437a572159788820ad40bcf7e84 to your computer and use it in GitHub Desktop.
# 0.6 Approach
using BenchmarkTools
using NullableArrays
n = 10_000_000
x = rand(n)
y = NullableArray{Float64}(n)
for i in 1:n
if !iseven(i)
y[i] = x[i]
end
end
sum(x)
sum(y)
@benchmark sum($x)
@benchmark sum($y)
# 0.7 Approach
using BenchmarkTools
n = 10_000_000
x = rand(n)
y = [ifelse(iseven(i), missing, x[i]) for i in 1:n]
sum(x)
sum(y)
@benchmark sum($x)
@benchmark sum($y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment