Comparing version 2.1.2 to 2.1.3
/** | ||
* The Benchmark instance for keeping track of the benchmark tasks and controlling | ||
* them. | ||
*/ | ||
declare class Bench extends EventTarget { | ||
#private; | ||
signal?: AbortSignal; | ||
warmupTime: number; | ||
warmupIterations: number; | ||
time: number; | ||
iterations: number; | ||
now: () => number; | ||
setup: Hook; | ||
teardown: Hook; | ||
constructor(options?: Options); | ||
/** | ||
* run the added tasks that were registered using the | ||
* `add` method | ||
*/ | ||
run(): Promise<Task[]>; | ||
/** | ||
* warmup the benchmark tasks | ||
*/ | ||
warmup(): Promise<void>; | ||
/** | ||
* reset each task and remove its result | ||
*/ | ||
reset(): void; | ||
/** | ||
* add a benchmark task to the task map | ||
*/ | ||
add(name: string, fn: Fn): this; | ||
/** | ||
* remove a benchmark task from the task map | ||
*/ | ||
remove(name: string): this; | ||
addEventListener(type: BenchEvents, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
removeEventListener(type: BenchEvents, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; | ||
/** | ||
* (getter) tasks results as an array | ||
*/ | ||
get results(): (TaskResult | undefined)[]; | ||
/** | ||
* (getter) tasks as an array | ||
*/ | ||
get tasks(): Task[]; | ||
/** | ||
* get a task based on the task name | ||
*/ | ||
getTask(name: string): Task | undefined; | ||
} | ||
/** | ||
* A class that represents each benchmark task in Tinybench. It keeps track of the | ||
@@ -79,4 +27,4 @@ * results, name, Bench instance, the task function and the number times the task | ||
warmup(): Promise<void>; | ||
addEventListener(type: TaskEvents, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
removeEventListener(type: TaskEvents, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; | ||
addEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(type: K, listener: T, options?: boolean | AddEventListenerOptions): void; | ||
removeEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(type: K, listener: T, options?: boolean | EventListenerOptions): void; | ||
/** | ||
@@ -220,2 +168,17 @@ * change the result object values | ||
type NoopEventListener = () => any | Promise<any> | ||
type TaskEventListener = (e: Event & { task: Task }) => any | Promise<any> | ||
interface BenchEventsMap{ | ||
abort: NoopEventListener | ||
start: NoopEventListener | ||
complete: NoopEventListener | ||
warmup: NoopEventListener | ||
reset: NoopEventListener | ||
add: TaskEventListener | ||
remove: TaskEventListener | ||
cycle: TaskEventListener | ||
error: TaskEventListener | ||
} | ||
/** | ||
@@ -233,2 +196,11 @@ * task events | ||
type TaskEventsMap = { | ||
abort: NoopEventListener | ||
start: TaskEventListener | ||
error: TaskEventListener | ||
cycle: TaskEventListener | ||
complete: TaskEventListener | ||
warmup: TaskEventListener | ||
reset: TaskEventListener | ||
} | ||
type Options = { | ||
@@ -280,4 +252,56 @@ /** | ||
/** | ||
* The Benchmark instance for keeping track of the benchmark tasks and controlling | ||
* them. | ||
*/ | ||
declare class Bench extends EventTarget { | ||
#private; | ||
signal?: AbortSignal; | ||
warmupTime: number; | ||
warmupIterations: number; | ||
time: number; | ||
iterations: number; | ||
now: () => number; | ||
setup: Hook; | ||
teardown: Hook; | ||
constructor(options?: Options); | ||
/** | ||
* run the added tasks that were registered using the | ||
* `add` method | ||
*/ | ||
run(): Promise<Task[]>; | ||
/** | ||
* warmup the benchmark tasks | ||
*/ | ||
warmup(): Promise<void>; | ||
/** | ||
* reset each task and remove its result | ||
*/ | ||
reset(): void; | ||
/** | ||
* add a benchmark task to the task map | ||
*/ | ||
add(name: string, fn: Fn): this; | ||
/** | ||
* remove a benchmark task from the task map | ||
*/ | ||
remove(name: string): this; | ||
addEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(type: K, listener: T, options?: boolean | AddEventListenerOptions): void; | ||
removeEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(type: K, listener: T, options?: boolean | EventListenerOptions): void; | ||
/** | ||
* (getter) tasks results as an array | ||
*/ | ||
get results(): (TaskResult | undefined)[]; | ||
/** | ||
* (getter) tasks as an array | ||
*/ | ||
get tasks(): Task[]; | ||
/** | ||
* get a task based on the task name | ||
*/ | ||
getTask(name: string): Task | undefined; | ||
} | ||
declare const now: () => number; | ||
export { Bench, BenchEvent, BenchEvents, Fn, Hook, Options, Task, TaskEvents, TaskResult, Bench as default, now }; |
@@ -1,8 +0,8 @@ | ||
var q = Object.defineProperty; | ||
var z = (s, r, t) => r in s ? q(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t; | ||
var a = (s, r, t) => (z(s, typeof r != "symbol" ? r + "" : r, t), t), V = (s, r, t) => { | ||
var j = Object.defineProperty; | ||
var q = (s, r, t) => r in s ? j(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t; | ||
var a = (s, r, t) => (q(s, typeof r != "symbol" ? r + "" : r, t), t), z = (s, r, t) => { | ||
if (!r.has(s)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var c = (s, r, t) => (V(s, r, "read from private field"), t ? t.call(s) : r.get(s)), M = (s, r, t) => { | ||
var c = (s, r, t) => (z(s, r, "read from private field"), t ? t.call(s) : r.get(s)), K = (s, r, t) => { | ||
if (r.has(s)) | ||
@@ -25,3 +25,3 @@ throw TypeError("Cannot add the same private member more than once"); | ||
// src/constants.ts | ||
var N = { | ||
var V = { | ||
1: 12.71, | ||
@@ -148,9 +148,9 @@ 2: 4.303, | ||
infinity: 1.96 | ||
}, g = N; | ||
}, T = V; | ||
// src/utils.ts | ||
var _ = (s) => s / 1e6, T = () => { | ||
var N = (s) => s / 1e6, g = () => { | ||
var s; | ||
return typeof ((s = globalThis.process) == null ? void 0 : s.hrtime) == "function" ? _(Number(process.hrtime.bigint())) : performance.now(); | ||
}, R = (s) => s.reduce((r, t) => r + t, 0) / s.length || 0, j = (s, r) => s.reduce((n, e) => n + (e - r) ** 2) / (s.length - 1) || 0; | ||
return typeof ((s = globalThis.process) == null ? void 0 : s.hrtime) == "function" ? N(Number(process.hrtime.bigint())) : performance.now(); | ||
}, R = (s) => s.reduce((r, t) => r + t, 0) / s.length || 0, O = (s, r) => s.reduce((n, e) => n + (e - r) ** 2) / (s.length - 1) || 0; | ||
@@ -169,3 +169,3 @@ // src/task.ts | ||
async run() { | ||
var o, l, v; | ||
var o, l, d; | ||
this.dispatchEvent(i("start", this)); | ||
@@ -185,3 +185,3 @@ let t = this.bench.now(), n = 0, e = []; | ||
{ | ||
let u = e[0], p = e[e.length - 1], w = n / this.runs, F = 1 / w, f = R(e), k = j(e, f), L = Math.sqrt(k), y = L / Math.sqrt(e.length), x = e.length - 1, O = g[String(Math.round(x) || 1)] || g.infinity, B = y * O, I = B / f * 100 || 0, P = e[Math.ceil(e.length * (75 / 100)) - 1], H = e[Math.ceil(e.length * (99 / 100)) - 1], A = e[Math.ceil(e.length * (99.5 / 100)) - 1], S = e[Math.ceil(e.length * (99.9 / 100)) - 1]; | ||
let u = e[0], p = e[e.length - 1], w = n / this.runs, F = 1 / w, f = R(e), k = O(e, f), y = Math.sqrt(k), x = y / Math.sqrt(e.length), M = e.length - 1, B = T[String(Math.round(M) || 1)] || T.infinity, L = x * B, I = L / f * 100 || 0, P = e[Math.ceil(e.length * (75 / 100)) - 1], H = e[Math.ceil(e.length * (99 / 100)) - 1], A = e[Math.ceil(e.length * (99.5 / 100)) - 1], S = e[Math.ceil(e.length * (99.9 / 100)) - 1]; | ||
if ((l = this.bench.signal) != null && l.aborted) | ||
@@ -198,7 +198,7 @@ return this; | ||
variance: k, | ||
sd: L, | ||
sem: y, | ||
df: x, | ||
critical: O, | ||
moe: B, | ||
sd: y, | ||
sem: x, | ||
df: M, | ||
critical: B, | ||
moe: L, | ||
rme: I, | ||
@@ -211,3 +211,3 @@ p75: P, | ||
} | ||
return (v = this.result) != null && v.error && (this.dispatchEvent(i("error", this)), this.bench.dispatchEvent(i("error", this))), this.dispatchEvent(i("cycle", this)), this.bench.dispatchEvent(i("cycle", this)), this.dispatchEvent(i("complete", this)), this; | ||
return (d = this.result) != null && d.error && (this.dispatchEvent(i("error", this)), this.bench.dispatchEvent(i("error", this))), this.dispatchEvent(i("cycle", this)), this.bench.dispatchEvent(i("cycle", this)), this.dispatchEvent(i("complete", this)), this; | ||
} | ||
@@ -244,5 +244,5 @@ async warmup() { | ||
constructor(t = {}) { | ||
var n, e, o, l, v, u, p; | ||
var n, e, o, l, d, u, p; | ||
super(); | ||
M(this, h, /* @__PURE__ */ new Map()); | ||
K(this, h, /* @__PURE__ */ new Map()); | ||
a(this, "signal"); | ||
@@ -253,6 +253,6 @@ a(this, "warmupTime", 100); | ||
a(this, "iterations", 10); | ||
a(this, "now", T); | ||
a(this, "now", g); | ||
a(this, "setup"); | ||
a(this, "teardown"); | ||
this.now = (n = t.now) != null ? n : this.now, this.warmupTime = (e = t.warmupTime) != null ? e : this.warmupTime, this.warmupIterations = (o = t.warmupIterations) != null ? o : this.warmupIterations, this.time = (l = t.time) != null ? l : this.time, this.iterations = (v = t.iterations) != null ? v : this.iterations, this.signal = t.signal, this.setup = (u = t.setup) != null ? u : () => { | ||
this.now = (n = t.now) != null ? n : this.now, this.warmupTime = (e = t.warmupTime) != null ? e : this.warmupTime, this.warmupIterations = (o = t.warmupIterations) != null ? o : this.warmupIterations, this.time = (l = t.time) != null ? l : this.time, this.iterations = (d = t.iterations) != null ? d : this.iterations, this.signal = t.signal, this.setup = (u = t.setup) != null ? u : () => { | ||
}, this.teardown = (p = t.teardown) != null ? p : () => { | ||
@@ -313,3 +313,3 @@ }, this.signal && this.signal.addEventListener("abort", () => { | ||
st as default, | ||
T as now | ||
g as now | ||
}; |
{ | ||
"name": "tinybench", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "packageManager": "pnpm@7.5.1", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31129
893