Skip to content

Commit

Permalink
Migrate benchmarks to vitest bench
Browse files Browse the repository at this point in the history
Compile legacy implementations for a fair and realistic benchmark comparison.
Remove obsolete benchmarks.

ref #20
  • Loading branch information
frostburn committed Apr 19, 2024
1 parent 0536280 commit b4f6922
Show file tree
Hide file tree
Showing 10 changed files with 841 additions and 1,107 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
benchmarks/
legacy/
dist/
docs/
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ dist
# TypeDoc
docs

# Benchmark
benchmarks
# Compiled legacy artifacts
legacy
1,451 changes: 628 additions & 823 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
],
"types": "dist/index.d.ts",
"devDependencies": {
"@types/benchmark": "^2.1.5",
"@types/node": "^20.10.1",
"benchmark": "^2.1.4",
"gts": "^5.2.0",
"typedoc": "^0.25.4",
"typescript": "^5.3.2",
"vitest": "^0.34.6"
"@types/node": "^20.12.7",
"gts": "^5.3.0",
"typedoc": "^0.25.13",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
},
"scripts": {
"lint": "gts lint",
Expand All @@ -44,13 +42,10 @@
"pretest": "npm run compile",
"posttest": "npm run lint",
"test": "vitest",
"doc": "typedoc src/index.ts . --name xen-dev-utils",
"premonzo-benchmark": "tsc -p tsconfig-benchmark.json",
"monzo-benchmark": "node benchmarks/__benchmarks__/monzo.mark.js",
"preprimes-benchmark": "tsc -p tsconfig-benchmark.json",
"primes-benchmark": "node benchmarks/__benchmarks__/primes.mark.js",
"prefraction-benchmark": "tsc -p tsconfig-benchmark.json",
"fraction-benchmark": "node benchmarks/__benchmarks__/fraction.mark.js"
"compile-legacy": "tsc -p tsconfig-legacy.json",
"prebench": "npm run compile && npm run compile-legacy",
"bench": "vitest bench",
"doc": "typedoc src/index.ts . --name xen-dev-utils"
},
"engines": {
"node": ">=10.6.0"
Expand Down
48 changes: 0 additions & 48 deletions src/__benchmarks__/fraction.mark.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/__benchmarks__/monzo.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {describe, bench} from 'vitest';

// It's important to use the distributed versions for a realistic comparison
import {toMonzoLegacy, primeLimitLegacy} from '../../legacy/legacy';
import {toMonzo, primeLimit} from '../../dist';

function randInt() {
return Math.ceil(Math.random() * 1000000000);
}

describe('Number to prime exponent vector conversion', () => {
bench('Old implementation', () => {
try {
toMonzoLegacy(randInt());
} catch {}
});

bench('Using probes without division', () => {
try {
toMonzo(randInt());
} catch {}
});
});

describe('Prime limit calculator', () => {
bench('Old implementation', () => {
primeLimitLegacy(randInt());
});

bench('New implementation', () => {
primeLimit(randInt());
});
});
174 changes: 0 additions & 174 deletions src/__benchmarks__/monzo.mark.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/__benchmarks__/primes.mark.ts

This file was deleted.

Loading

0 comments on commit b4f6922

Please sign in to comment.