Socket
Socket
Sign inDemoInstall

tinybench

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinybench - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

20

dist/index.d.ts

@@ -189,3 +189,4 @@ /**

| 'add' // when a Task gets added to the Bench
| 'remove'; // when a Task gets removed of the Bench
| 'remove' // when a Task gets removed of the Bench
| 'todo'; // when a todo Task gets added to the Bench

@@ -207,2 +208,3 @@ type Hook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;

error: TaskEventListener
todo: TaskEventListener
}

@@ -283,2 +285,3 @@

_tasks: Map<string, Task>;
_todos: Map<string, Task>;
signal?: AbortSignal;

@@ -313,2 +316,6 @@ warmupTime: number;

/**
* add a benchmark todo to the todo map
*/
todo(name: string, fn?: Fn, opts?: FnOptions): this;
/**
* remove a benchmark task from the task map

@@ -320,2 +327,12 @@ */

/**
* table of the tasks results
*/
table(): ({
'Task Name': string;
'ops/sec': string;
'Average Time (ns)': number;
Margin: string;
Samples: number;
} | null)[];
/**
* (getter) tasks results as an array

@@ -328,2 +345,3 @@ */

get tasks(): Task[];
get todos(): Task[];
/**

@@ -330,0 +348,0 @@ * get a task based on the task name

68

dist/index.js

@@ -1,4 +0,4 @@

var H = Object.defineProperty;
var P = (n, a, t) => a in n ? H(n, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[a] = t;
var i = (n, a, t) => (P(n, typeof a != "symbol" ? a + "" : a, t), t);
var S = Object.defineProperty;
var H = (n, a, t) => a in n ? S(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);

@@ -17,3 +17,3 @@ // src/event.ts

// src/constants.ts
var S = {
var z = {
1: 12.71,

@@ -140,10 +140,10 @@ 2: 4.303,

infinity: 1.96
}, b = S;
}, w = z;
// src/utils.ts
var j = (n) => n / 1e6, w = () => {
var P = (n) => n / 1e6, b = () => {
var n;
return typeof ((n = globalThis.process) == null ? void 0 : n.hrtime) == "function" ? j(Number(process.hrtime.bigint())) : performance.now();
}, B = (n) => n.reduce((a, t) => a + t, 0) / n.length || 0, F = (n, a) => n.reduce((e, s) => e + (s - a) ** 2) / (n.length - 1) || 0, q = (async () => {
}).constructor, O = (n) => n.constructor === q;
return typeof ((n = globalThis.process) == null ? void 0 : n.hrtime) == "function" ? P(Number(process.hrtime.bigint())) : performance.now();
}, F = (n) => n.reduce((a, t) => a + t, 0) / n.length || 0, B = (n, a) => n.reduce((e, s) => e + (s - a) ** 2) / (n.length - 1) || 0, j = (async () => {
}).constructor, O = (n) => n.constructor === j;

@@ -179,3 +179,3 @@ // src/task.ts

{
let h = e[0], c = e[e.length - 1], f = t / this.runs, L = 1e3 / f, E = B(e), T = F(e, E), k = Math.sqrt(T), g = k / Math.sqrt(e.length), y = e.length - 1, x = b[String(Math.round(y) || 1)] || b.infinity, M = g * x, K = M / E * 100 || 0, A = e[Math.ceil(e.length * (75 / 100)) - 1], R = e[Math.ceil(e.length * (99 / 100)) - 1], _ = e[Math.ceil(e.length * (99.5 / 100)) - 1], I = e[Math.ceil(e.length * (99.9 / 100)) - 1];
let h = e[0], c = e[e.length - 1], f = t / this.runs, L = 1e3 / f, E = F(e), g = B(e, E), T = Math.sqrt(g), k = T / Math.sqrt(e.length), y = e.length - 1, x = w[String(Math.round(y) || 1)] || w.infinity, M = k * x, A = M / E * 100 || 0, K = e[Math.ceil(e.length * (75 / 100)) - 1], _ = e[Math.ceil(e.length * (99 / 100)) - 1], R = e[Math.ceil(e.length * (99.5 / 100)) - 1], I = e[Math.ceil(e.length * (99.9 / 100)) - 1];
if ((u = this.bench.signal) != null && u.aborted)

@@ -191,12 +191,12 @@ return this;

mean: E,
variance: T,
sd: k,
sem: g,
variance: g,
sd: T,
sem: k,
df: y,
critical: x,
moe: M,
rme: K,
p75: A,
p99: R,
p995: _,
rme: A,
p75: K,
p99: _,
p995: R,
p999: I

@@ -211,3 +211,3 @@ });

let t = this.bench.now(), e = 0;
for (this.bench.setup(this, "warmup"); (e < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((s = this.bench.signal) != null && s.aborted); ) {
for (await this.bench.setup(this, "warmup"); (e < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((s = this.bench.signal) != null && s.aborted); ) {
try {

@@ -241,2 +241,3 @@ await Promise.resolve().then(this.fn);

i(this, "_tasks", /* @__PURE__ */ new Map());
i(this, "_todos", /* @__PURE__ */ new Map());
i(this, "signal");

@@ -247,3 +248,3 @@ i(this, "warmupTime", 100);

i(this, "iterations", 10);
i(this, "now", w);
i(this, "now", b);
i(this, "setup");

@@ -253,5 +254,9 @@ i(this, "teardown");

}, this.teardown = (c = t.teardown) != null ? c : () => {
}, this.signal && this.signal.addEventListener("abort", () => {
this.dispatchEvent(r("abort"));
}, { once: !0 });
}, this.signal && this.signal.addEventListener(
"abort",
() => {
this.dispatchEvent(r("abort"));
},
{ once: !0 }
);
}

@@ -280,2 +285,7 @@ async run() {

}
todo(t, e = () => {
}, s = {}) {
let o = new p(this, t, e, s);
return this._todos.set(t, o), this.dispatchEvent(r("todo", o)), this;
}
remove(t) {

@@ -291,2 +301,11 @@ let e = this.getTask(t);

}
table() {
return this.tasks.map(({ name: t, result: e }) => e ? {
"Task Name": t,
"ops/sec": parseInt(e.hz.toString(), 10).toLocaleString(),
"Average Time (ns)": e.mean * 1e3 * 1e3,
Margin: `\xB1${e.rme.toFixed(2)}%`,
Samples: e.samples.length
} : null);
}
get results() {

@@ -298,2 +317,5 @@ return [...this._tasks.values()].map((t) => t.result);

}
get todos() {
return [...this._todos.values()];
}
getTask(t) {

@@ -310,3 +332,3 @@ return this._tasks.get(t);

tt as default,
w as now
b as now
};
{
"name": "tinybench",
"version": "2.4.0",
"version": "2.5.0",
"type": "module",

@@ -20,2 +20,21 @@ "packageManager": "pnpm@7.5.1",

"license": "MIT",
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.4",
"@size-limit/time": "^7.0.8",
"@types/node": "^18.7.13",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"bumpp": "^8.2.0",
"changelogithub": "^0.12.4",
"clean-publish": "^3.4.4",
"eslint": "^8.22.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"nano-staged": "^0.5.0",
"size-limit": "^7.0.8",
"tsup": "^5.11.7",
"typescript": "^4.5.4",
"vite": "^2.9.12",
"vitest": "^0.14.2"
},
"keywords": [

@@ -27,4 +46,7 @@ "benchmark",

"scripts": {
"publish": "npm run build && clean-publish"
"dev": "tsup --watch",
"build": "tsup",
"release": "bumpp package.json --commit --push --tag && npm run publish",
"test": "vitest --no-threads"
}
}
}

@@ -35,28 +35,35 @@ # tinybench

bench
.add('switch 1', () => {
let a = 1;
let b = 2;
const c = a;
a = b;
b = c;
.add('faster task', () => {
console.log('I am faster')
})
.add('switch 2', () => {
let a = 1;
let b = 10;
a = b + a;
b = a - b;
a = b - a;
});
.add('slower task', async () => {
await new Promise(r => setTimeout(r, 1)) // we wait 1ms :)
console.log('I am slower')
})
.todo('unimplemented bench')
await bench.run();
console.table(bench.tasks.map(({ name, result }) => ({ "Task Name": name, "Average Time (ps)": result?.mean * 1000, "Variance (ps)": result?.variance * 1000 })));
console.table(bench.table());
// Output:
// ┌─────────┬────────────┬────────────────────┬────────────────────┐
// │ (index) │ Task Name │ Average Time (ps) │ Variance (ps) │
// ├─────────┼────────────┼────────────────────┼────────────────────┤
// │ 0 │ 'switch 1' │ 1.8458325710527104 │ 1.2113875253341617 │
// │ 1 │ 'switch 2' │ 1.8746935152109603 │ 1.2254725890767446 │
// └─────────┴────────────┴────────────────────┴────────────────────┘
// ┌─────────┬───────────────┬──────────┬────────────────────┬───────────┬─────────┐
// │ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
// ├─────────┼───────────────┼──────────┼────────────────────┼───────────┼─────────┤
// │ 0 │ 'faster task' │ '41,621' │ 24025.791819761525 │ '±20.50%' │ 4257 │
// │ 1 │ 'slower task' │ '828' │ 1207382.7838323202 │ '±7.07%' │ 83 │
// └─────────┴───────────────┴──────────┴────────────────────┴───────────┴─────────┘
console.table(
bench.todos.map(({ name }) => ({
'Task name': name,
})),
);
// Output:
// ┌─────────┬───────────────────────┐
// │ (index) │ Task name │
// ├─────────┼───────────────────────┤
// │ 0 │ 'unimplemented bench' │
// └─────────┴───────────────────────┘
```

@@ -140,5 +147,8 @@

- `remove(name: string)`: remove a benchmark task from the task map
- `table()`: table of the tasks results
- `get results(): (TaskResult | undefined)[]`: (getter) tasks results as an array
- `get tasks(): Task[]`: (getter) tasks as an array
- `getTask(name: string): Task | undefined`: get a task based on the name
- `todo(name: string, fn?: Fn, opts: FnOptions)`: add a benchmark todo to the todo map
- `get todos(): Task[]`: (getter) tasks todos as an array

@@ -309,3 +319,4 @@ ### `Task`

| "add" // when a Task gets added to the Bench
| "remove"; // when a Task gets removed of the Bench
| "remove" // when a Task gets removed of the Bench
| "todo"; // when a todo Task gets added to the Bench

@@ -366,1 +377,11 @@ /**

Feel free to create issues/discussions and then PRs for the project!
## Sponsors
Your sponsorship can make a huge difference in continuing our work in open source!
<p align="center">
<a href="https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg'/>
</a>
</p>

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc