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

benchmark: use a bitwise right shift for faster division #2658

Closed
wants to merge 1 commit into from
Closed

benchmark: use a bitwise right shift for faster division #2658

wants to merge 1 commit into from

Conversation

JungMinu
Copy link
Member

@JungMinu JungMinu commented Sep 2, 2015

Division in Javascript is known to be very slow
use a Bitwise right shift for faster division for better performance

Division in Javascript is known to be very slow
use a Bitwise right shift for faster division for better performance
@JungMinu
Copy link
Member Author

JungMinu commented Sep 2, 2015

Please refer to the following article for the performance review
http://jorshasaur.us/faster-multiplication-and-division-in-javascript/

@mscdex
Copy link
Contributor

mscdex commented Sep 2, 2015

This particular change is outside of the actual timing, so it's not going to affect the actual results. Besides, making the benchmarks themselves faster is less beneficial than making the code that the benchmarks are testing, faster.

@mscdex mscdex added the benchmark Issues and PRs related to the benchmark subsystem. label Sep 2, 2015
@JungMinu
Copy link
Member Author

JungMinu commented Sep 2, 2015

@mscdex Thanks, then do you think that this PR should be closed?

@mscdex
Copy link
Contributor

mscdex commented Sep 2, 2015

Also FWIW the article you linked to was written with Chrome 35 in mind which is quite old. This jsperf shows that Chrome 45 for example optimizes all of the various methods given in the article so they all perform the same.

@ChALkeR
Copy link
Member

ChALkeR commented Sep 2, 2015

The only change here is replacing new Array(len / 2 + 1).join('ü'); with new Array(len >> 1 + 1).join('ü');, where minimum used len is 102400.

I really doubt that this would make any measurable difference here, when comparing a single division of a number by 2 with allocating a new Array of 51201 elements and then joining it's elements using 'ü' as a divisor to get a string with 51200 utf chars.

Also, as @mscdex mentioned, that's outside of the timing, it's just preparation code.

@Trott
Copy link
Member

Trott commented Sep 4, 2015

Closing this one based on discussion above. Feel free to re-open if you think that's premature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark Issues and PRs related to the benchmark subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants