question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Am I doing something wrong: asmcrypto way slower than other libs with sha256

See original GitHub issue

Hi.

I made a little benchmark to compare asmcrypto with two other popular node.js crypto libs and my tests show that it’s way slower than them, which is unexpected considering that performance is the main point of your lib:

let asm = require('asmcrypto.js');

start = process.hrtime();

for (let i = 0; i < 100000; i++) {
    asm.SHA256
        .hex('abcdefghijklmnopqrstuvwxyz')
    ;
}

diff = process.hrtime(start);

console.log((diff[0] * 1e9 + diff[1]) / 1e6 + 'ms');

let shajs = require('sha.js');

start = process.hrtime();

for (let i = 0; i < 100000; i++) {
    shajs('sha256')
        .update('abcdefghijklmnopqrstuvwxyz')
        .digest('hex')
    ;
}

diff = process.hrtime(start);

console.log((diff[0] * 1e9 + diff[1]) / 1e6 + 'ms');

let crypto = require('crypto');

start = process.hrtime();

for (let i = 0; i < 100000; i++) {
    crypto
        .createHmac('sha256', '')
        .update('abcdefghijklmnopqrstuvwxyz')
        .digest('hex')
    ;
}

diff = process.hrtime(start);

console.log((diff[0] * 1e9 + diff[1]) / 1e6 + 'ms');

On my system:

asmcrypto: ~650ms sha.js: ~370ms crypto: ~300ms

Is there something I’m doing wrong here? I’m already thinkng that other crypto libs are extremely slow (for comparison, PHP hash function execute that test in ~70ms - yes, seventy!) and was hoping asmcrypto would solve that issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jochenonlinecommented, Mar 26, 2018

@ericmorand : asmcrypto is asm.js / WebCrypto is binary. So on server side any binary implementation will beat asmcrypto.

0reactions
ericmorandcommented, Mar 26, 2018

Ooooh, sorry, I missed that part. Thanks for your clarification and patience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why SHA-256 (or any other) is too fast for passwords but "slow ...
Since SHA-256 is much faster than dedicated password hashing functions, you can test guesses for colliding pairs much faster than you could ......
Read more >
Create SHA-256 hash from a Blob/File in javascript
From what I've found, CryptoJS is the only one that supports hashing an ArrayBuffer directly, which is way faster than going through base-64,...
Read more >
CryptoKit: SHA256 much much slower than `CryptoSwift`
Hey, CryptoKit's SHA256 (using it twice), is 3 times slower than CryptoSwift's implementation. I was hoping it would be the other way around....
Read more >
Performance worse than sjcl lib · Issue #18 - GitHub
Since iojs v3 and node v4, Buffer is a subclass of Uint8Array . So .buffer should work just fine!
Read more >
Why does Scrypt run so much slower than sha256? - Reddit
Before I start I am aware this is a question related to cryptocurrency but the question itself is regarding hashing algorithms so I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found