sisl / GridInterpolations.jl

Multidimensional grid interpolation in arbitrary dimensions
Other
52 stars 12 forks source link

any(isnan.(x)) -> any(isnan, x) #27

Closed zsunberg closed 4 years ago

zsunberg commented 4 years ago

For some reason this is much faster

julia> x = [1.0, 4.0, NaN, 3.0]

julia> @benchmark any(isnan.($x))
BenchmarkTools.Trial: 
  memory estimate:  4.31 KiB
  allocs estimate:  3
  --------------
  minimum time:     535.708 ns (0.00% GC)
  median time:      608.789 ns (0.00% GC)
  mean time:        1.256 μs (17.10% GC)
  maximum time:     224.575 μs (99.41% GC)
  --------------
  samples:          10000
  evals/sample:     178

julia> @benchmark any(map(isnan, $x))
BenchmarkTools.Trial: 
  memory estimate:  112 bytes
  allocs estimate:  2
  --------------
  minimum time:     32.824 ns (0.00% GC)
  median time:      36.619 ns (0.00% GC)
  mean time:        47.285 ns (16.65% GC)
  maximum time:     40.261 μs (99.81% GC)
  --------------
  samples:          10000
  evals/sample:     989
zsunberg commented 4 years ago

Actually...

julia> @benchmark any(isnan(t) for t in $x)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     3.146 ns (0.00% GC)
  median time:      3.613 ns (0.00% GC)
  mean time:        3.780 ns (0.00% GC)
  maximum time:     44.120 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000
zsunberg commented 4 years ago
julia> @benchmark any(isnan, $x)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     2.792 ns (0.00% GC)
  median time:      2.946 ns (0.00% GC)
  mean time:        3.095 ns (0.00% GC)
  maximum time:     17.228 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000
coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.6%) to 94.863% when pulling 498ee63dd7cd33da69ca9b6ddf91ce8874309279 on zsunberg-patch-1 into 934bcdc4961353d8e80d590a1409a0e7d4d964b6 on master.