Skip to content

Commit

Permalink
chore: benchmarks should not cache the object between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Jul 23, 2024
1 parent fe49ab5 commit ebbe88b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions bench/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@ const getObject = () => {
};
};

suite<any>(
suite<unknown>(
{
'object-identity'() {
return (o) => identify(o);
return () => identify(getObject());
},
'object-hash'() {
const options = { algorithm: 'passthrough', unorderedSets: false };

return (o) => objectHash(o, options);
return () => objectHash(getObject(), options);
},
'json-stable-stringify'() {
return (o) => jsonStableStringify(o);
return () => jsonStableStringify(getObject());
},
'tiny-stable-stringify'() {
return (o) => tinyStableStringify(o);
return () => tinyStableStringify(getObject());
},
},
(run) => {
const o = getObject();
run(undefined, () => o);
run(undefined);
},
{
size: 50,
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ assert.toEqual(hashA, hashB);
> via the [`/bench`](/bench) directory with deno 1.45.2
```
✔ object-identity ~ 13,888,888 ops/sec ± 2.35%
✔ object-hash ~ 126,262 ops/sec ± 0.20%
✔ json-stable-stringify ~ 664,893 ops/sec ± 0.51%
✔ tiny-stable-stringify ~ 642,673 ops/sec ± 0.50%
✔ object-identity ~ 313,676 ops/sec ± 0.39%
✔ object-hash ~ 88,873 ops/sec ± 0.16%
✔ json-stable-stringify ~ 444,839 ops/sec ± 0.41%
✔ tiny-stable-stringify ~ 520,833 ops/sec ± 0.45%
```

> ^ `object-identity` is not as feature-full it's alternatives, specifically around `function`
Expand Down

0 comments on commit ebbe88b

Please sign in to comment.