Created
June 18, 2018 10:22
-
-
Save johnmyleswhite/cd13a437a572159788820ad40bcf7e84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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