Skip to content

Instantly share code, notes, and snippets.

@johnmyleswhite
Created June 27, 2018 12:28
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/915a8f4834db23f29170e7f28b09eef6 to your computer and use it in GitHub Desktop.
Save johnmyleswhite/915a8f4834db23f29170e7f28b09eef6 to your computer and use it in GitHub Desktop.
Perf of Missing Values in Julia 0.7
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)
@johnmyleswhite
Copy link
Author

julia> @benchmark sum($x)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0

minimum time: 4.633 ms (0.00% GC)
median time: 5.285 ms (0.00% GC)
mean time: 5.444 ms (0.00% GC)
maximum time: 10.290 ms (0.00% GC)

samples: 916
evals/sample: 1

julia> @benchmark sum($y)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0

minimum time: 10.661 ms (0.00% GC)
median time: 11.276 ms (0.00% GC)
mean time: 11.606 ms (0.00% GC)
maximum time: 22.728 ms (0.00% GC)

samples: 430
evals/sample: 1

@johnmyleswhite
Copy link
Author

library("microbenchmark")

n <- 10000000

x <- runif(n)

sum(x)

microbenchmark(sum(x))
> microbenchmark(sum(x))
Unit: milliseconds
   expr      min       lq     mean   median       uq      max neval
 sum(x) 9.147777 9.415088 9.938853 9.656602 10.27017 12.09193   100

@StefanKarpinski
Copy link

It seems like comparing with R where there are NAs present would make sense, no?

@jlapeyre
Copy link

jlapeyre commented Jul 4, 2018

Almost the same benchmarks appear in First-Class Statistical Missing Values Support in Julia 0.7 (do a page seach for "always allow"), but an R example with NAs is included. The result is the same as here: the R example without NAs is 2x slower than the Julia example. The R example with NAs is 2x again slower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment