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

Array operations optimization #8

Merged
merged 3 commits into from
Jul 24, 2014
Merged

Array operations optimization #8

merged 3 commits into from
Jul 24, 2014

Conversation

dcousens
Copy link
Contributor

As demonstrated by http://jsperf.com/base58-array-ops, and even a basic understanding should make it clear, using unshift is much slower than using push in Array operations as each unshift is an O(n) operation.

This change just reverses the operation order on the array so as push becomes possible, with a single O(n) reversal done at the end of the function.
On Chrome, this gives a slight (~10-15%) improvement, but on Firefox 30 it gives up to a 50% improvement in ops/sec.

@dcousens dcousens changed the title Opti Array operations optimization Jul 24, 2014
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling dede3a7 on dcousens:opti into 7d29b77 on cryptocoinjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling fd805f7 on dcousens:opti into 7d29b77 on cryptocoinjs:master.

jprichardson added a commit that referenced this pull request Jul 24, 2014
Array operations optimization
@jprichardson jprichardson merged commit 2286e2a into cryptocoinjs:master Jul 24, 2014
@jprichardson
Copy link
Member

Looks good, thanks!

@dcousens dcousens deleted the opti branch July 25, 2014 00:58
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.

3 participants