benchmark.js 621 B

12345678910111213141516171819202122
  1. const { hash: hashWasm } = require('./dist/node');
  2. const { hash: hashNative } = require('./dist/node-native');
  3. const { createHash } = require('crypto');
  4. [
  5. { size: '64B', data: Buffer.alloc(64) },
  6. { size: '64KB', data: Buffer.alloc(1024 * 64) },
  7. { size: '6MB', data: Buffer.alloc(1024 * 1024 * 6) },
  8. ].forEach(({ size, data }) =>
  9. suite(size, () => {
  10. ['md5', 'sha1', 'sha256'].forEach(alg =>
  11. bench(alg, () =>
  12. createHash(alg)
  13. .update(data)
  14. .digest(),
  15. ),
  16. );
  17. bench('blake3 wasm', () => hashWasm(data));
  18. bench('blake3 native', () => hashNative(data));
  19. }),
  20. );