Skip to content

Conversation

@H4ad
Copy link
Contributor

@H4ad H4ad commented Apr 22, 2023

This is the benchmark that I was using during the tests and improvements.

@H4ad H4ad mentioned this pull request Apr 22, 2023
@codecov
Copy link

codecov bot commented Apr 22, 2023

Codecov Report

Merging #39 (7306825) into main (23431de) will increase coverage by 0.11%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   80.37%   80.49%   +0.11%     
==========================================
  Files           8        8              
  Lines         968      979      +11     
  Branches      125      126       +1     
==========================================
+ Hits          778      788      +10     
- Misses        190      191       +1     

see 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

},
"license": "MIT",
"dependencies": {
"benchmark": "2.1.4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer it to be a top level devDependency. Benchmark is part of same repo same as tests for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I'm not sure how I can do that with pnpm without touching in tsconfig.json.

Copy link
Member

@pi0 pi0 Apr 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me push to the branch (i don't have push access)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added you as a collaborator to my fork, but I think you can easily modify this PR by using Github CLI.

@@ -0,0 +1,67 @@
const Benchmark = require('benchmark');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not using .mjs for ESM syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not run easily with .ts or .mjs, so instead of fighting with these things I just use commonjs.

But we can change to use .ts, I just don't know how I can make this work in this repo ahashuhas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest node versions have native esm support. We also have jiti here and it uses native ts => cjs/esm transform but it might little bit affect perf.

@H4ad
Copy link
Contributor Author

H4ad commented Apr 22, 2023

The new performance with all changes merged:

hash({}) x 1,049,485 ops/sec ±0.89% (90 runs sampled)
hash(singleObject) x 137,249 ops/sec ±0.53% (96 runs sampled)
hash(tinyArray) x 14,593 ops/sec ±0.48% (94 runs sampled)
hash(mediumArray) x 1,490 ops/sec ±0.12% (95 runs sampled)
hash(largeArray) x 136 ops/sec ±1.04% (75 runs sampled)
hash(largeJson) x 3.37 ops/sec ±3.75% (13 runs sampled)
objectHash(largeJson, { unorderedObjects: true }) x 3.16 ops/sec ±3.80% (13 runs sampled)

To compare, this was the benchmark without the perf improvements:

hash({}) x 718,939 ops/sec ±2.05% (83 runs sampled)
hash(singleObject) x 98,894 ops/sec ±1.05% (94 runs sampled)
hash(tinyArray) x 10,602 ops/sec ±0.40% (93 runs sampled)
hash(mediumArray) x 1,030 ops/sec ±1.49% (91 runs sampled)
hash(largeArray) x 67.91 ops/sec ±1.90% (70 runs sampled)
hash(largeJson) x 1.86 ops/sec ±1.52% (9 runs sampled)
objectHash(largeJson, { unorderedObjects: true }) x 1.86 ops/sec ±2.21% (9 runs sampled)

@pi0
Copy link
Member

pi0 commented Apr 22, 2023

New changes on M2:

hash({}) x 2,634,385 ops/sec ±1.11% (93 runs sampled)
hash(singleObject) x 264,012 ops/sec ±0.08% (98 runs sampled)
hash(tinyArray) x 27,163 ops/sec ±0.23% (101 runs sampled)
hash(mediumArray) x 2,669 ops/sec ±0.38% (100 runs sampled)
hash(largeArray) x 168 ops/sec ±0.50% (87 runs sampled)
hash(largeJson) x 2.88 ops/sec ±1.17% (12 runs sampled)
objectHash(largeJson, { unorderedObjects: true }) x 2.79 ops/sec ±4.94% (11 runs sampled)
Fastest is hash({})

@pi0 pi0 mentioned this pull request Apr 22, 2023
@pi0
Copy link
Member

pi0 commented Apr 22, 2023

Moving to #40 since i don't have push access to amend here. Thanks for quick and amazing contribs ❤️

@pi0 pi0 closed this Apr 22, 2023
@H4ad H4ad deleted the chore/add-benchmark branch April 22, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants