browserify / sha.js

Streamable SHA hashes in pure javascript
Other
288 stars 60 forks source link

Improve performace #34

Closed fanatid closed 8 years ago

fanatid commented 8 years ago

Significant performance improvement for sha, sha1, sha256 (sha512 not much): benchmark for sha256 (crypto-bench at daf5e83):

$ node -v
v5.6.0
$ SEED=123 node bench-hash.js sha.js sha256
...
20, 56, 7763.84, 0.007212925562608194
21, 68, 6926.48, 0.0098173964264677
22, 84, 11534.88, 0.007282260413632392
23, 102, 13698.6, 0.007446016381236039
24, 125, 13043.75, 0.009583133684714902
...
76, 4466835, 23509.657894736843, 190
77, 5463865, 21943.232931726907, 249
78, 6683439, 22057.554455445545, 303
79, 8175230, 24187.07100591716, 338
80, 10000000, 22573.363431151243, 443

for current version of sha.js and hash.js here

/cc @dcousens @indutny

dcousens commented 8 years ago

Very nice.

dcousens commented 8 years ago

Nice loop unrolling. ACK. Haven't tested performance locally yet.

fanatid commented 8 years ago

kudos @indutny

fanatid commented 8 years ago

@dcousens I just add |0 to some variables, probably you skip them, unroll loops like in hash.js. Also make benchmarks with unsigned.. signed is faster.

dcousens commented 8 years ago

@fanatid that is a huge improvement over hash.js though.

fanatid commented 8 years ago

because signed is used (hash.js uses unsigned), inline some functions and as I understand |0 is faster than >>> 0

dcousens commented 8 years ago

Verified performance improvement. Merging. @dominictarr please release :)

dominictarr commented 8 years ago

awesome great work!

On Tue, Feb 16, 2016 at 9:41 AM, Daniel Cousens notifications@github.com wrote:

Merged #34 https://github.com/crypto-browserify/sha.js/pull/34.

— Reply to this email directly or view it on GitHub https://github.com/crypto-browserify/sha.js/pull/34#event-551190373.

fanatid commented 8 years ago

Can you publish package with this PR?

fanatid commented 8 years ago

ping @dcousens