Comparing version 2.1.5 to 2.2.0
@@ -271,2 +271,6 @@ /** | ||
/** | ||
* works like {@link run} but runs the tasks sequentially, see #17 for more information | ||
*/ | ||
runSequentially(): Promise<Task[]>; | ||
/** | ||
* warmup the benchmark tasks. | ||
@@ -273,0 +277,0 @@ * This is not run by default by the {@link run} method. |
@@ -1,16 +0,16 @@ | ||
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)) | ||
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 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)) | ||
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(s) : r.set(s, t); | ||
r instanceof WeakSet ? r.add(n) : r.set(n, t); | ||
}; | ||
// src/event.ts | ||
function i(s, r = null) { | ||
let t = new Event(s); | ||
function i(n, r = null) { | ||
let t = new Event(n); | ||
return Object.defineProperty(t, "task", { | ||
@@ -150,10 +150,10 @@ value: r, | ||
// src/utils.ts | ||
var N = (s) => s / 1e6, g = () => { | ||
var s; | ||
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; | ||
var N = (n) => n / 1e6, g = () => { | ||
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; | ||
// src/task.ts | ||
var l = class extends EventTarget { | ||
constructor(t, n, e) { | ||
constructor(t, s, e) { | ||
super(); | ||
@@ -165,31 +165,31 @@ a(this, "bench"); | ||
a(this, "result"); | ||
this.bench = t, this.name = n, this.fn = e; | ||
this.bench = t, this.name = s, this.fn = e; | ||
} | ||
async run() { | ||
var o, u, d; | ||
var c, m, d; | ||
this.dispatchEvent(i("start", this)); | ||
let t = this.bench.now(), n = 0, e = []; | ||
for (await this.bench.setup(this, "run"); (n < this.bench.time || this.runs < this.bench.iterations) && !((o = this.bench.signal) != null && o.aborted); ) { | ||
let p = 0; | ||
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; | ||
try { | ||
await Promise.resolve().then(() => (p = this.bench.now(), this.fn())); | ||
} catch (b) { | ||
this.setResult({ error: b }); | ||
await Promise.resolve().then(() => (u = this.bench.now(), this.fn())); | ||
} catch (w) { | ||
this.setResult({ error: w }); | ||
} | ||
let m = this.bench.now() - p; | ||
this.runs += 1, e.push(m), n = this.bench.now() - t; | ||
let p = this.bench.now() - u; | ||
this.runs += 1, e.push(p), s = this.bench.now() - t; | ||
} | ||
await this.bench.teardown(this, "run"), e.sort(); | ||
{ | ||
let p = e[0], m = e[e.length - 1], b = n / this.runs, F = 1 / b, 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, P = L / f * 100 || 0, I = 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 ((u = this.bench.signal) != null && u.aborted) | ||
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) | ||
return this; | ||
this.setResult({ | ||
totalTime: n, | ||
min: p, | ||
max: m, | ||
totalTime: s, | ||
min: u, | ||
max: p, | ||
hz: F, | ||
period: b, | ||
period: w, | ||
samples: e, | ||
mean: f, | ||
mean: b, | ||
variance: k, | ||
@@ -204,4 +204,4 @@ sd: y, | ||
p99: H, | ||
p995: A, | ||
p999: S | ||
p995: S, | ||
p999: q | ||
}); | ||
@@ -214,17 +214,17 @@ } | ||
this.dispatchEvent(i("warmup", this)); | ||
let t = this.bench.now(), n = 0; | ||
for (this.bench.setup(this, "warmup"); (n < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((e = this.bench.signal) != null && e.aborted); ) { | ||
let t = this.bench.now(), s = 0; | ||
for (this.bench.setup(this, "warmup"); (s < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((e = this.bench.signal) != null && e.aborted); ) { | ||
try { | ||
await Promise.resolve().then(this.fn); | ||
} catch (o) { | ||
} catch (c) { | ||
} | ||
this.runs += 1, n = this.bench.now() - t; | ||
this.runs += 1, s = this.bench.now() - t; | ||
} | ||
this.bench.teardown(this, "warmup"), this.runs = 0; | ||
} | ||
addEventListener(t, n, e) { | ||
super.addEventListener(t, n, e); | ||
addEventListener(t, s, e) { | ||
super.addEventListener(t, s, e); | ||
} | ||
removeEventListener(t, n, e) { | ||
super.removeEventListener(t, n, e); | ||
removeEventListener(t, s, e) { | ||
super.removeEventListener(t, s, e); | ||
} | ||
@@ -240,5 +240,5 @@ setResult(t) { | ||
// src/bench.ts | ||
var h, w = class extends EventTarget { | ||
var h, f = class extends EventTarget { | ||
constructor(t = {}) { | ||
var n, e, o, u, d, p, m; | ||
var s, e, c, m, d, u, p; | ||
super(); | ||
@@ -254,4 +254,4 @@ K(this, h, /* @__PURE__ */ new Map()); | ||
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 = (u = t.time) != null ? u : this.time, this.iterations = (d = t.iterations) != null ? d : this.iterations, this.signal = t.signal, this.setup = (p = t.setup) != null ? p : () => { | ||
}, this.teardown = (m = t.teardown) != null ? m : () => { | ||
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 : () => { | ||
}, this.signal && this.signal.addEventListener("abort", () => { | ||
@@ -263,42 +263,48 @@ this.dispatchEvent(i("abort")); | ||
this.dispatchEvent(i("start")); | ||
let t = await Promise.all([...c(this, h).entries()].map(async ([n, e]) => { | ||
var o; | ||
return (o = this.signal) != null && o.aborted ? e : await new Promise((u) => setTimeout(async () => { | ||
u(await e.run()); | ||
})); | ||
let t = await Promise.all([...o(this, h).values()].map((s) => { | ||
var e; | ||
return (e = this.signal) != null && e.aborted ? s : new Promise((c) => setTimeout(() => s.run().then(c))); | ||
})); | ||
return this.dispatchEvent(i("complete")), t; | ||
} | ||
async runSequentially() { | ||
var s; | ||
this.dispatchEvent(i("start")); | ||
let t = []; | ||
for (let e of [...o(this, h).values()]) | ||
(s = this.signal) != null && s.aborted && t.push(e), t.push(await e.run()); | ||
return this.dispatchEvent(i("complete")), t; | ||
} | ||
async warmup() { | ||
this.dispatchEvent(i("warmup")); | ||
for (let [, t] of c(this, h)) | ||
for (let [, t] of o(this, h)) | ||
await t.warmup(); | ||
} | ||
reset() { | ||
this.dispatchEvent(i("reset")), c(this, h).forEach((t) => { | ||
this.dispatchEvent(i("reset")), o(this, h).forEach((t) => { | ||
t.reset(); | ||
}); | ||
} | ||
add(t, n) { | ||
let e = new l(this, t, n); | ||
return c(this, h).set(t, e), this.dispatchEvent(i("add", e)), this; | ||
add(t, s) { | ||
let e = new l(this, t, s); | ||
return o(this, h).set(t, e), this.dispatchEvent(i("add", e)), this; | ||
} | ||
remove(t) { | ||
let n = this.getTask(t); | ||
return this.dispatchEvent(i("remove", n)), c(this, h).delete(t), this; | ||
let s = this.getTask(t); | ||
return this.dispatchEvent(i("remove", s)), o(this, h).delete(t), this; | ||
} | ||
addEventListener(t, n, e) { | ||
super.addEventListener(t, n, e); | ||
addEventListener(t, s, e) { | ||
super.addEventListener(t, s, e); | ||
} | ||
removeEventListener(t, n, e) { | ||
super.removeEventListener(t, n, e); | ||
removeEventListener(t, s, e) { | ||
super.removeEventListener(t, s, e); | ||
} | ||
get results() { | ||
return [...c(this, h).values()].map((t) => t.result); | ||
return [...o(this, h).values()].map((t) => t.result); | ||
} | ||
get tasks() { | ||
return [...c(this, h).values()]; | ||
return [...o(this, h).values()]; | ||
} | ||
getTask(t) { | ||
return c(this, h).get(t); | ||
return o(this, h).get(t); | ||
} | ||
@@ -309,5 +315,5 @@ }; | ||
// src/index.ts | ||
var st = w; | ||
var st = f; | ||
export { | ||
w as Bench, | ||
f as Bench, | ||
l as Task, | ||
@@ -314,0 +320,0 @@ st as default, |
{ | ||
"name": "tinybench", | ||
"version": "2.1.5", | ||
"version": "2.2.0", | ||
"type": "module", | ||
@@ -18,11 +18,4 @@ "packageManager": "pnpm@7.5.1", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tinylibs/tinyspy.git" | ||
}, | ||
"repository": "tinylibs/tinybench", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/tinylibs/tinyspy/issues" | ||
}, | ||
"homepage": "https://github.com/tinylibs/tinyspy#readme", | ||
"keywords": [ | ||
@@ -29,0 +22,0 @@ "benchmark", |
@@ -129,2 +129,4 @@ # tinybench | ||
- `async run()`: run the added tasks that were registered using the `add` method | ||
- `async runSequentially()`: works like `run` but runs the tasks | ||
sequentially, see [#17](https://github.com/tinylibs/tinybench/issues/17) for more information | ||
- `async warmup()`: warm up the benchmark tasks | ||
@@ -131,0 +133,0 @@ - `reset()`: reset each task and remove its result |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
34461
915
335
2
1
1