Comparing version 2.2.0 to 2.2.1
@@ -254,3 +254,3 @@ /** | ||
declare class Bench extends EventTarget { | ||
#private; | ||
_tasks: Map<string, Task>; | ||
signal?: AbortSignal; | ||
@@ -257,0 +257,0 @@ warmupTime: number; |
@@ -1,18 +0,10 @@ | ||
var A = Object.defineProperty; | ||
var j = (n, r, t) => r in n ? A(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t; | ||
var a = (n, r, t) => (j(n, typeof r != "symbol" ? r + "" : r, t), t), z = (n, r, t) => { | ||
if (!r.has(n)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var o = (n, r, t) => (z(n, r, "read from private field"), t ? t.call(n) : r.get(n)), K = (n, r, t) => { | ||
if (r.has(n)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
r instanceof WeakSet ? r.add(n) : r.set(n, t); | ||
}; | ||
var I = Object.defineProperty; | ||
var H = (n, a, t) => a in n ? I(n, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[a] = t; | ||
var i = (n, a, t) => (H(n, typeof a != "symbol" ? a + "" : a, t), t); | ||
// src/event.ts | ||
function i(n, r = null) { | ||
function r(n, a = null) { | ||
let t = new Event(n); | ||
return Object.defineProperty(t, "task", { | ||
value: r, | ||
value: a, | ||
enumerable: !0, | ||
@@ -25,3 +17,3 @@ writable: !1, | ||
// src/constants.ts | ||
var V = { | ||
var S = { | ||
1: 12.71, | ||
@@ -148,66 +140,66 @@ 2: 4.303, | ||
infinity: 1.96 | ||
}, T = V; | ||
}, w = S; | ||
// src/utils.ts | ||
var N = (n) => n / 1e6, g = () => { | ||
var q = (n) => n / 1e6, b = () => { | ||
var n; | ||
return typeof ((n = globalThis.process) == null ? void 0 : n.hrtime) == "function" ? N(Number(process.hrtime.bigint())) : performance.now(); | ||
}, R = (n) => n.reduce((r, t) => r + t, 0) / n.length || 0, O = (n, r) => n.reduce((s, e) => s + (e - r) ** 2) / (n.length - 1) || 0; | ||
return typeof ((n = globalThis.process) == null ? void 0 : n.hrtime) == "function" ? q(Number(process.hrtime.bigint())) : performance.now(); | ||
}, B = (n) => n.reduce((a, t) => a + t, 0) / n.length || 0, L = (n, a) => n.reduce((s, e) => s + (e - a) ** 2) / (n.length - 1) || 0; | ||
// src/task.ts | ||
var l = class extends EventTarget { | ||
var u = class extends EventTarget { | ||
constructor(t, s, e) { | ||
super(); | ||
a(this, "bench"); | ||
a(this, "name"); | ||
a(this, "fn"); | ||
a(this, "runs", 0); | ||
a(this, "result"); | ||
i(this, "bench"); | ||
i(this, "name"); | ||
i(this, "fn"); | ||
i(this, "runs", 0); | ||
i(this, "result"); | ||
this.bench = t, this.name = s, this.fn = e; | ||
} | ||
async run() { | ||
var c, m, d; | ||
this.dispatchEvent(i("start", this)); | ||
var h, p, l; | ||
this.dispatchEvent(r("start", this)); | ||
let t = this.bench.now(), s = 0, e = []; | ||
for (await this.bench.setup(this, "run"); (s < this.bench.time || this.runs < this.bench.iterations) && !((c = this.bench.signal) != null && c.aborted); ) { | ||
let u = 0; | ||
for (await this.bench.setup(this, "run"); (s < this.bench.time || this.runs < this.bench.iterations) && !((h = this.bench.signal) != null && h.aborted); ) { | ||
let o = 0; | ||
try { | ||
await Promise.resolve().then(() => (u = this.bench.now(), this.fn())); | ||
} catch (w) { | ||
this.setResult({ error: w }); | ||
await Promise.resolve().then(() => (o = this.bench.now(), this.fn())); | ||
} catch (E) { | ||
this.setResult({ error: E }); | ||
} | ||
let p = this.bench.now() - u; | ||
this.runs += 1, e.push(p), s = this.bench.now() - t; | ||
let c = this.bench.now() - o; | ||
this.runs += 1, e.push(c), s = this.bench.now() - t; | ||
} | ||
await this.bench.teardown(this, "run"), e.sort(); | ||
{ | ||
let u = e[0], p = e[e.length - 1], w = s / this.runs, F = 1 / w, b = R(e), k = O(e, b), 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, P = L / b * 100 || 0, I = e[Math.ceil(e.length * (75 / 100)) - 1], H = e[Math.ceil(e.length * (99 / 100)) - 1], S = e[Math.ceil(e.length * (99.5 / 100)) - 1], q = e[Math.ceil(e.length * (99.9 / 100)) - 1]; | ||
if ((m = this.bench.signal) != null && m.aborted) | ||
let o = e[0], c = e[e.length - 1], E = s / this.runs, K = 1 / E, f = B(e), T = L(e, f), k = Math.sqrt(T), g = k / Math.sqrt(e.length), y = e.length - 1, x = w[String(Math.round(y) || 1)] || w.infinity, M = g * x, R = M / f * 100 || 0, _ = e[Math.ceil(e.length * (75 / 100)) - 1], O = e[Math.ceil(e.length * (99 / 100)) - 1], F = e[Math.ceil(e.length * (99.5 / 100)) - 1], P = e[Math.ceil(e.length * (99.9 / 100)) - 1]; | ||
if ((p = this.bench.signal) != null && p.aborted) | ||
return this; | ||
this.setResult({ | ||
totalTime: s, | ||
min: u, | ||
max: p, | ||
hz: F, | ||
period: w, | ||
min: o, | ||
max: c, | ||
hz: K, | ||
period: E, | ||
samples: e, | ||
mean: b, | ||
variance: k, | ||
sd: y, | ||
sem: x, | ||
df: M, | ||
critical: B, | ||
moe: L, | ||
rme: P, | ||
p75: I, | ||
p99: H, | ||
p995: S, | ||
p999: q | ||
mean: f, | ||
variance: T, | ||
sd: k, | ||
sem: g, | ||
df: y, | ||
critical: x, | ||
moe: M, | ||
rme: R, | ||
p75: _, | ||
p99: O, | ||
p995: F, | ||
p999: P | ||
}); | ||
} | ||
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; | ||
return (l = this.result) != null && l.error && (this.dispatchEvent(r("error", this)), this.bench.dispatchEvent(r("error", this))), this.dispatchEvent(r("cycle", this)), this.bench.dispatchEvent(r("cycle", this)), this.dispatchEvent(r("complete", this)), this; | ||
} | ||
async warmup() { | ||
var e; | ||
this.dispatchEvent(i("warmup", this)); | ||
this.dispatchEvent(r("warmup", this)); | ||
let t = this.bench.now(), s = 0; | ||
@@ -217,3 +209,3 @@ for (this.bench.setup(this, "warmup"); (s < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((e = this.bench.signal) != null && e.aborted); ) { | ||
await Promise.resolve().then(this.fn); | ||
} catch (c) { | ||
} catch (h) { | ||
} | ||
@@ -234,3 +226,3 @@ this.runs += 1, s = this.bench.now() - t; | ||
reset() { | ||
this.dispatchEvent(i("reset", this)), this.runs = 0, this.result = void 0; | ||
this.dispatchEvent(r("reset", this)), this.runs = 0, this.result = void 0; | ||
} | ||
@@ -240,44 +232,44 @@ }; | ||
// src/bench.ts | ||
var h, f = class extends EventTarget { | ||
var v = class extends EventTarget { | ||
constructor(t = {}) { | ||
var s, e, c, m, d, u, p; | ||
var s, e, h, p, l, o, c; | ||
super(); | ||
K(this, h, /* @__PURE__ */ new Map()); | ||
a(this, "signal"); | ||
a(this, "warmupTime", 100); | ||
a(this, "warmupIterations", 5); | ||
a(this, "time", 500); | ||
a(this, "iterations", 10); | ||
a(this, "now", g); | ||
a(this, "setup"); | ||
a(this, "teardown"); | ||
this.now = (s = t.now) != null ? s : this.now, this.warmupTime = (e = t.warmupTime) != null ? e : this.warmupTime, this.warmupIterations = (c = t.warmupIterations) != null ? c : this.warmupIterations, this.time = (m = t.time) != null ? m : 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 : () => { | ||
i(this, "_tasks", /* @__PURE__ */ new Map()); | ||
i(this, "signal"); | ||
i(this, "warmupTime", 100); | ||
i(this, "warmupIterations", 5); | ||
i(this, "time", 500); | ||
i(this, "iterations", 10); | ||
i(this, "now", b); | ||
i(this, "setup"); | ||
i(this, "teardown"); | ||
this.now = (s = t.now) != null ? s : this.now, this.warmupTime = (e = t.warmupTime) != null ? e : this.warmupTime, this.warmupIterations = (h = t.warmupIterations) != null ? h : this.warmupIterations, this.time = (p = t.time) != null ? p : this.time, this.iterations = (l = t.iterations) != null ? l : this.iterations, this.signal = t.signal, this.setup = (o = t.setup) != null ? o : () => { | ||
}, this.teardown = (c = t.teardown) != null ? c : () => { | ||
}, this.signal && this.signal.addEventListener("abort", () => { | ||
this.dispatchEvent(i("abort")); | ||
this.dispatchEvent(r("abort")); | ||
}, { once: !0 }); | ||
} | ||
async run() { | ||
this.dispatchEvent(i("start")); | ||
let t = await Promise.all([...o(this, h).values()].map((s) => { | ||
this.dispatchEvent(r("start")); | ||
let t = await Promise.all([...this._tasks.values()].map((s) => { | ||
var e; | ||
return (e = this.signal) != null && e.aborted ? s : new Promise((c) => setTimeout(() => s.run().then(c))); | ||
return (e = this.signal) != null && e.aborted ? s : new Promise((h) => setTimeout(() => s.run().then(h))); | ||
})); | ||
return this.dispatchEvent(i("complete")), t; | ||
return this.dispatchEvent(r("complete")), t; | ||
} | ||
async runSequentially() { | ||
var s; | ||
this.dispatchEvent(i("start")); | ||
this.dispatchEvent(r("start")); | ||
let t = []; | ||
for (let e of [...o(this, h).values()]) | ||
for (let e of [...this._tasks.values()]) | ||
(s = this.signal) != null && s.aborted && t.push(e), t.push(await e.run()); | ||
return this.dispatchEvent(i("complete")), t; | ||
return this.dispatchEvent(r("complete")), t; | ||
} | ||
async warmup() { | ||
this.dispatchEvent(i("warmup")); | ||
for (let [, t] of o(this, h)) | ||
this.dispatchEvent(r("warmup")); | ||
for (let [, t] of this._tasks) | ||
await t.warmup(); | ||
} | ||
reset() { | ||
this.dispatchEvent(i("reset")), o(this, h).forEach((t) => { | ||
this.dispatchEvent(r("reset")), this._tasks.forEach((t) => { | ||
t.reset(); | ||
@@ -287,8 +279,8 @@ }); | ||
add(t, s) { | ||
let e = new l(this, t, s); | ||
return o(this, h).set(t, e), this.dispatchEvent(i("add", e)), this; | ||
let e = new u(this, t, s); | ||
return this._tasks.set(t, e), this.dispatchEvent(r("add", e)), this; | ||
} | ||
remove(t) { | ||
let s = this.getTask(t); | ||
return this.dispatchEvent(i("remove", s)), o(this, h).delete(t), this; | ||
return this.dispatchEvent(r("remove", s)), this._tasks.delete(t), this; | ||
} | ||
@@ -302,20 +294,19 @@ addEventListener(t, s, e) { | ||
get results() { | ||
return [...o(this, h).values()].map((t) => t.result); | ||
return [...this._tasks.values()].map((t) => t.result); | ||
} | ||
get tasks() { | ||
return [...o(this, h).values()]; | ||
return [...this._tasks.values()]; | ||
} | ||
getTask(t) { | ||
return o(this, h).get(t); | ||
return this._tasks.get(t); | ||
} | ||
}; | ||
h = new WeakMap(); | ||
// src/index.ts | ||
var st = f; | ||
var Z = v; | ||
export { | ||
f as Bench, | ||
l as Task, | ||
st as default, | ||
g as now | ||
v as Bench, | ||
u as Task, | ||
Z as default, | ||
b as now | ||
}; |
{ | ||
"name": "tinybench", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"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
33822
897