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

Faster IntMap.size and IntSet.size #1062

Open
meooow25 opened this issue Nov 2, 2024 · 0 comments
Open

Faster IntMap.size and IntSet.size #1062

meooow25 opened this issue Nov 2, 2024 · 0 comments

Comments

@meooow25
Copy link
Contributor

meooow25 commented Nov 2, 2024

I've been playing around with a few alternative implementations for IntMap.size to see if it can be made faster, and interestingly it seems it can.

Here are the implementations: https://gist.github.com/meooow25/0864ec79ad7885b470bf3d927b4deffa

And results on my machine with GHC 9.10.1:

  asc
    size:       OK
      2.08 μs ± 179 ns
    sizeNoNil:  OK
      1.66 μs ± 105 ns, 0.80x
    sizeUnroll: OK
      1.54 μs ± 124 ns, 0.74x
    size2:      OK
      1.33 μs ±  22 ns, 0.64x
    size3:      OK
      1.14 μs ± 102 ns, 0.55x
    size4:      OK
      1.16 μs ±  51 ns, 0.56x
    sizeStack2: OK
      1.49 μs ±  61 ns, 0.71x
  rand
    size:       OK
      2.17 μs ± 149 ns
    sizeNoNil:  OK
      2.02 μs ± 179 ns, 0.93x
    sizeUnroll: OK
      2.53 μs ± 188 ns, 1.17x
    size2:      OK
      1.52 μs ± 115 ns, 0.70x
    size3:      OK
      1.36 μs ± 108 ns, 0.63x
    size4:      OK
      1.56 μs ± 119 ns, 0.72x
    sizeStack2: OK
      1.43 μs ±  94 ns, 0.66x

Of course, these are still O(n) (#763), but being faster doesn't hurt.

size3 seems to be doing the best so we could switch to it, unless someone offers a faster implementation.

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

No branches or pull requests

1 participant