| 1 | import hashObject from 'hash-object' |
| 2 | import { hasher } from 'node-object-hash' |
| 3 | import hash from 'object-hash' |
| 4 | import { bench, group, run } from 'tatami-ng' |
| 5 | |
| 6 | import { generateRandomObject } from './benchmark-utils.mjs' |
| 7 | |
| 8 | const object = generateRandomObject() |
| 9 | |
| 10 | group(`Hash object with ${Object.keys(object).length} keys`, () => { |
| 11 | bench('hash-object', (obj = object) => { |
| 12 | return hashObject(obj, { algorithm: 'sha256' }) |
| 13 | }) |
| 14 | bench('node-object-hash', (obj = object) => { |
| 15 | return hasher({ alg: 'sha256' }).hash(obj) |
| 16 | }) |
| 17 | bench('object-hash', (obj = object) => { |
| 18 | return hash(obj, { algorithm: 'sha256' }) |
| 19 | }) |
| 20 | }) |
| 21 | |
| 22 | await run({ |
| 23 | units: true, |
| 24 | }) |