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

Implement a faster and unbiased version of list shuffling #171

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

lehins
Copy link
Contributor

@lehins lehins commented Dec 22, 2024

Naive implementation using sorting lists is too slow. Here we add basic support of mutable boxed arrays and use it to implement Fisher-Yates shuffle algorithm that proves to be at least x20 more efficient

  shuffle
    uniformShuffleList:  OK (0.72s)
      5.43 ms ± 155 μs
    uniformShuffleListM: OK (0.21s)
      14.2 ms ± 818 μs
    naiveShuffleListM:   OK (0.92s)
      313  ms ± 5.7 ms

I thought about my implementation from #140 really hard and I could not release such naive implementation with a clear conscience. 🙂

Resolves #158

Naive implementation using sorting lists is too slow. Here we add basic
support of mutable boxed arrays and use it to implement Fisher-Yates shuffle
algorithm that proves to be at least x20 more efficient

```
  shuffle
    uniformShuffleList:  OK (0.72s)
      5.43 ms ± 155 μs
    uniformShuffleListM: OK (0.21s)
      14.2 ms ± 818 μs
    naiveShuffleListM:   OK (0.92s)
      313  ms ± 5.7 ms
```
@lehins lehins force-pushed the lehins/use-array-for-shuffle branch from 5acf53d to a79f427 Compare December 25, 2024 22:41
@lehins lehins merged commit fb9dcb1 into master Dec 26, 2024
52 checks passed
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

Successfully merging this pull request may close these issues.

Rewrite shuffleListM using array
1 participant