diff --git a/src/main.d.mts b/src/main.d.mts index 927e6ef..1887bb8 100644 --- a/src/main.d.mts +++ b/src/main.d.mts @@ -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; @@ -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; -} \ No newline at end of file +} diff --git a/src/main.mjs b/src/main.mjs index d0b58fa..3eb42ff 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -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) { @@ -1592,4 +1599,4 @@ export const $ = { canvas[canvas.length - 1] += !colors ? rmax : ($.magenta + rmax + $.reset); return canvas; }, }, -}; \ No newline at end of file +};