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

Optimize array_rand_weighted #19

Merged
merged 1 commit into from Mar 31, 2020

Conversation

Littlesqx
Copy link
Contributor

@Littlesqx Littlesqx commented Mar 31, 2020

I tested the performance of the new(array_rand_weighted_v2) and old(array_rand_weighted) functions, the result are as follows:

  • GROUP 1: time usage

array_rand_weighted

size times time usage (sec)
10 10000 0.021669864654541
100 10000 0.12856888771057
1000 10000 1.2416679859161
10000 10000 21.270864009857

array_rand_weighted_v2

size times time usage (sec)
10 10000 0.0097980499267578
100 10000 0.076462984085083
1000 10000 0.74438810348511
10000 10000 7.601450920105
  • GROUP 2: memory usage

array_rand_weighted

size times memory usage (byte)
10 10000 2097152
100 10000 2097152
1000 10000 2097152
10000 10000 6295552
50000 10000 23076864

array_rand_weighted_v2

size times memory usage (byte)
10 10000 2097152
100 10000 2097152
1000 10000 2097152
10000 10000 4194304
50000 10000 8396800

The benchmark code are here: gist link

@freekmurze freekmurze merged commit 39b0af9 into spatie:master Mar 31, 2020
@freekmurze
Copy link
Member

Thanks!

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.

None yet

2 participants