cryptocoinjs / bs58

Base58 encoding/decoding for Bitcoin
http://cryptocoinjs.com/modules/misc/bs58/
MIT License
216 stars 48 forks source link

Array operations optimization #8

Closed dcousens closed 10 years ago

dcousens commented 10 years ago

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.

coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling dede3a76de3320e2ee6c9464a934a4a2473b0197 on dcousens:opti into 7d29b7784a464b336de0a4b85f6d580588555882 on cryptocoinjs:master.

coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling fd805f7a732fa28ee57e364b4791f86ca3b462f9 on dcousens:opti into 7d29b7784a464b336de0a4b85f6d580588555882 on cryptocoinjs:master.

jprichardson commented 10 years ago

Looks good, thanks!