Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant performance cost over naively filtering indices #14

Open
ararslan opened this issue May 5, 2019 · 0 comments
Open

Significant performance cost over naively filtering indices #14

ararslan opened this issue May 5, 2019 · 0 comments

Comments

@ararslan
Copy link
Member

ararslan commented May 5, 2019

I went to port Jackknife over to use InvertedIndices, but I noticed something... suboptimal.

Below are some timings for using InvertedIndices (thing1) and using the current naive approach for skipping indices (thing2).

julia> using InvertedIndices, Statistics, BenchmarkTools

julia> thing1(f, x) = map(i->f(view(x, Not(i))), eachindex(x))
thing1 (generic function with 1 method)

julia> thing2(f, x) = (is = eachindex(x); map(i->f(view(x, filter(!isequal(i), is))), is))
thing2 (generic function with 1 method)

julia> x = randn(2000);

julia> @benchmark thing1(mean, $x)
BenchmarkTools.Trial:
  memory estimate:  792.91 MiB
  allocs estimate:  27954027
  --------------
  minimum time:     2.523 s (1.98% GC)
  median time:      2.564 s (2.81% GC)
  mean time:        2.564 s (2.81% GC)
  maximum time:     2.605 s (3.61% GC)
  --------------
  samples:          2
  evals/sample:     1

julia> @benchmark thing2(mean, $x)
BenchmarkTools.Trial:
  memory estimate:  35.48 MiB
  allocs estimate:  28005
  --------------
  minimum time:     18.324 ms (3.89% GC)
  median time:      20.482 ms (10.97% GC)
  mean time:        20.770 ms (11.10% GC)
  maximum time:     64.851 ms (64.83% GC)
  --------------
  samples:          241
  evals/sample:     1

That's pretty hardcore. Am I doing something wrong in how I'm using it here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant