Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ interface k_options {

// ---
export function bench(fn: () => any): B;
export function bench(fn: B): B;
export function do_not_optimize(v: any): void;
export function bench(name: string, fn: () => any): B;
export function bench(gen: (state: k_state) => Gen): B;
Expand Down Expand Up @@ -149,4 +150,4 @@ export class B {
name(name: string, highlight?: Color): this;
range(name: string, s: number, e: number, multiplier?: number): this;
dense_range(name: string, s: number, e: number, accumulator?: number): this;
}
}
13 changes: 10 additions & 3 deletions src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ export function lineplot(f) { return _c(f, 'l'); }
export function group(name, f) { if (typeof name === 'function') (f = name, name = null); return _c(f, 'g', name); }

export function bench(n, fn) {
if (typeof n === 'function') (fn = n, n = fn.name || 'anonymous');
let b;
if(n instanceof B) {
b = n
}else {
if (typeof n === 'function') (fn = n, n = fn.name || 'anonymous');
b = new B(n, fn);
}

const collection = COLLECTIONS[COLLECTIONS.length - 1];
const b = new B(n, fn); b._group = collection.id; return (collection.trials.push(b), b);
b._group = collection.id;
return (collection.trials.push(b), b);
}

export function compact(f) {
Expand Down Expand Up @@ -1592,4 +1599,4 @@ export const $ = {
canvas[canvas.length - 1] += !colors ? rmax : ($.magenta + rmax + $.reset); return canvas;
},
},
};
};