Skip to content

Preallocate result array for range #116

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

Merged
merged 2 commits into from
Oct 1, 2017

Conversation

jacereda
Copy link
Contributor

For range 0 1000:

No prealloc:

   range/1000           6020.450 ns 0.998 r2       166100.536 ops/s 

Prealloc:

   range/1000           3720.389 ns 0.995 r2       268789.072 ops/s 

@jacereda
Copy link
Contributor Author

Ups, I always forget range is inclusive...

@jacereda
Copy link
Contributor Author

With the correct size:

   range/1000           2580.780 ns 0.998 r2       387479.709 ops/s 

@@ -7,7 +7,7 @@
exports.range = function (start) {
return function (end) {
var step = start > end ? -1 : 1;
var result = [];
var result = new Array(step * (end - start) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. Isn't this too large when step > 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? It can only be -1 or 1...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry, I misread 🤦‍♂️

@paf31 paf31 merged commit 0210025 into purescript:master Oct 1, 2017
@paf31
Copy link
Contributor

paf31 commented Oct 1, 2017

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.

2 participants