Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evanwashere/mitata
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 262783fb36ba60900c78d9b456bb110d4a0343c2
Choose a base ref
...
head repository: evanwashere/mitata
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db92ead36f5543311f14591ef9b07dd5a224eef3
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 9, 2025

  1. @mitata/counters: 0.0.8

    - recompile with latest zig
    evanwashere committed Jan 9, 2025
    Copy the full SHA
    96bef4e View commit details
  2. 1.0.27

    - ignore errors from hardware counters
    evanwashere committed Jan 9, 2025
    Copy the full SHA
    db92ead View commit details
Showing with 21 additions and 12 deletions.
  1. +1 −1 counters/package.json
  2. +1 −1 package.json
  3. +6 −5 src/lib.mjs
  4. +13 −5 tools/compare.mjs
2 changes: 1 addition & 1 deletion counters/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"license": "MIT",
"version": "0.0.7",
"version": "0.0.8",
"main": "src/lib.mjs",
"name": "@mitata/counters",
"files": ["dist/*", "src/lib.mjs"],
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "mitata",
"type": "module",
"license": "MIT",
"version": "1.0.26",
"version": "1.0.27",
"main": "src/main.mjs",
"types": "src/main.d.mts",
"files": ["src", "license", "readme.md"],
11 changes: 6 additions & 5 deletions src/lib.mjs
Original file line number Diff line number Diff line change
@@ -173,7 +173,8 @@ export async function fn(fn, opts = {}) {
}

const loop = new AsyncFunction('$fn', '$gc', '$now', '$params', '$counters', `
${!opts.$counters ? '' : 'try { $counters.init(); '}
${!opts.$counters ? '' : 'let _hc = false;'}
${!opts.$counters ? '' : 'try { $counters.init(); _hc = true; } catch {}'}
let _ = 0; let t = 0;
let samples = new Array(2 ** 20);
@@ -216,7 +217,7 @@ export async function fn(fn, opts = {}) {
}
`}
${!opts.$counters ? '' : '$counters.before();'} const t0 = $now();
${!opts.$counters ? '' : 'if (_hc) try { $counters.before(); } catch {};'} const t0 = $now();
${!batch ? `
${!async ? '' : (1 >= opts.concurrency ? '' : 'await Promise.all([')}
@@ -246,7 +247,7 @@ export async function fn(fn, opts = {}) {
}
`}
const t1 = $now(); ${!opts.$counters ? '' : '$counters.after();'}
const t1 = $now(); ${!opts.$counters ? '' : 'if (_hc) try { $counters.after(); } catch {};'}
const diff = t1 - t0;
samples[_] = diff ${!batch ? '' : `/ ${opts.batch_samples}`};
@@ -268,10 +269,10 @@ export async function fn(fn, opts = {}) {
p999: samples[(.999 * (samples.length - 1)) | 0],
avg: samples.reduce((a, v) => a + v, 0) / samples.length,
ticks: samples.length ${!batch ? '' : `* ${opts.batch_samples}`},
${!opts.$counters ? '' : `counters: $counters.translate(${!batch ? 1 : opts.batch_samples}, samples.length),`}
${!opts.$counters ? '' : `...(!_hc ? {} : { counters: $counters.translate(${!batch ? 1 : opts.batch_samples}, samples.length) }),`}
};
${!opts.$counters ? '' : '} finally { $counters.deinit(); }'}
${!opts.$counters ? '' : 'if (_hc) try { $counters.deinit(); } catch {};'}
`);

return {
18 changes: 13 additions & 5 deletions tools/compare.mjs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ const b = () => {
import { run, bench } from 'mitata';

if (isMainThread) {
bench('a / b (warmup)', () => b()).compact();
bench('a / b', () => b());

bench('a / b (computed)', function* () {
@@ -34,7 +35,7 @@ if (isMainThread) {
};
});

console.log(`${$.time((await run()).benchmarks[0].runs[0].stats.avg)}/iter - https://npmjs.com/mitata`);
console.log(`${$.time((await run()).benchmarks[1].runs[0].stats.avg)}/iter - https://npmjs.com/mitata`);
}

// benchmark.js - https://npmjs.com/benchmark
@@ -43,12 +44,13 @@ const { Suite } = Benchmark;

if (isMainThread) {
const suite = new Suite();
suite.add('a / b (warmup)', () => b());
suite.add('a / b', () => b());
suite.on('cycle', (event) => {
console.log(String(event.target));
console.log(`${$.time(1e9 * event.target.stats.mean)}/iter - https://npmjs.com/benchmark`);
if (event.target.name === 'a / b') console.log(`${$.time(1e9 * event.target.stats.mean)}/iter - https://npmjs.com/benchmark`);
});

await suite.run();
}

@@ -58,8 +60,9 @@ import { Bench } from 'tinybench';

if (isMainThread) {
const tb = new Bench();
tb.add('a / b (warmup)', () => b());
tb.add('a / b', () => b());

await tb.run();
console.table(tb.table());
console.log(`${$.time(1e6 * tb._tasks.get('a / b').result.mean)}/iter - vitest bench / https://npmjs.com/tinybench`);
@@ -70,14 +73,19 @@ import { Suite as BNSuite } from 'bench-node';

if (isMainThread) {
const nbsuite = new BNSuite();
nbsuite.add('a / b (warmup)', () => b());
nbsuite.add('a / b', () => b());
console.log(`${$.time((await nbsuite.run())[0].histogram.mean)}/iter - https://npmjs.com/bench-node`);
console.log(`${$.time((await nbsuite.run())[1].histogram.mean)}/iter - https://npmjs.com/bench-node`);
}

// cronometro - https://npmjs.com/cronometro
import cronometro from 'cronometro';

const results = await cronometro({
'a / b (warmup)'() {
return b();
},

'a / b'() {
return b();
},