test(serialize): improved benchmarking
I created a small util to automatically download specific versions from GitHub to compare with each other and the current version.
import { bench } from "vitest";
import { getVersions } from "./fixtures/utils/versions";
// Options for v1
const hashOptions = { unorderedArrays: true, unorderedSets: true };
const versions = await getVersions(["v1.1.5", "v2.0.4", "v2.0.11"]);
for (const version of versions) {
bench(version.name, () => {
version.serialize("hello world", hashOptions);
});
}
Added custom benchmarks.
Added the same benchmarks for bun using mitata.
Added bench:bun command to run the bun benchmark.
Tip: we can use "ohash-v1": "npm:ohash@^1" in devDependencies to have same effect.
Tip: we can use
"ohash-v1": "npm:ohash@^1"indevDependenciesto have same effect.
This allows me to use any branch name, commit hash or version tag to benchmark with the current dev version (and against each other). If I only wanted to bench dev with v1 that would have been an easier solution of course ๐๐ป
For example:
export const benchConfig: BenchConfig = {
versions: [
"v2.0.11",
"7a52c4ac82c33396c2e2ea90e2896ccf3a03256b",
"main",
],
...
}
benchmark avg (min โฆ max) p75 / p99 (min โฆ top 1%)
------------------------------------------- -------------------------------
โข count:1, size:small
------------------------------------------- -------------------------------
ohash @ v2.0.11 497.56 ns/iter 477.08 ns โโ
(457.46 ns โฆ 905.65 ns) 841.28 ns โโ
( 0.00 b โฆ 726.00 b) 12.63 b โโโโโโโโโโโโโโโโโโโโโ
ohash @ 7a52c4a 453.85 ns/iter 431.23 ns โโ
(415.98 ns โฆ 825.99 ns) 787.21 ns โโ
( 0.00 b โฆ 1.03 kb) 31.17 b โโโโโโโโโโโโโโโโโโโโโ
ohash @ main 475.14 ns/iter 448.85 ns โ
(431.98 ns โฆ 1.01 ยตs) 851.39 ns โโ
( 0.00 b โฆ 1.29 kb) 36.44 b โโโโโโโโโโโโโโโโโโโโโ
ohash @ dev 406.66 ns/iter 386.36 ns โโ
(370.59 ns โฆ 962.38 ns) 769.31 ns โโ
( 0.00 b โฆ 1.10 kb) 29.73 b โโโโโโโโโโโโโโโโโโโโโ
summary
ohash @ dev
1.12x faster than ohash @ 7a52c4a
1.17x faster than ohash @ main
1.22x faster than ohash @ v2.0.11
I decided to remove vitest benchmarks for serialize and use only mitata for both Bun and node for easier maintainabilty.
Added jiti as dev. dep. to use mitata with node.
Added the option to use arguments to turn on specific benchmarks (--presets (default) / --combined / --custom / --full).