Closed zdm closed 4 years ago
I ran some additional tests and I managed to reproduce your results. It seems that for small input buffers jsSHA is much faster in SHA-1.
Here are my measurements: 16 bytes => jssha is about 2.6x faster 256 bytes => jssha has similar performance compared to hash-wasm 1024 bytes => hash-wasm is about 2x faster 32 kilobytes => hash-wasm is about 7.7x faster
My benchmarks in the readme, were run on a 4MB input buffer. That's why we see a big difference there. Thank you for bringing up this issue. I will add some additional columns to the benchmark section to also compare the performance of hashing smaller chunks of data.
ok, thank you for clarifying,
I found a way to improve the performance for smaller input. You can check it out in v3.0.1.
Also, I added a new column with the 32 byte benchmark results.
Yes, I see, Thank you. Interesting, why your code is slow on small data?
You forgot to remove console.log from code.
await sha1( "123" );
prints to console.
I improved the performance further in version 3.1.1. Now it should be at least 2 times faster than jsSHA for short input strings.
I cannot reproduce the console.log
issue. I don't have console.logs in the code.
The bottleneck is the JavaScript -> WebAssembly boundary. Currently, the WASM function calls from JavaScript are very expensive. I managed to increase the performance by decreasing the number of WASM calls from 3 to 1 in case of small input data.
I think, that in the future these bottlenecks will disappear, while the JavaScript engine developers implement further optimizations for WASM.
Thank you, performance is amazing now.
My tests shows other values:
Test is simple hash calc. func, called in loop.
jssha
hash-wasm
What I am doing wrong?