first commit
This commit is contained in:
commit
eb2f504652
32490 changed files with 5731109 additions and 0 deletions
21
node_modules/tinybench/LICENSE
generated
vendored
Normal file
21
node_modules/tinybench/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Tinylibs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
383
node_modules/tinybench/README.md
generated
vendored
Normal file
383
node_modules/tinybench/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,383 @@
|
|||
# tinybench
|
||||
|
||||
Benchmark your code easily with Tinybench, a simple, tiny and light-weight `7KB` (`2KB` minified and gzipped)
|
||||
benchmarking library!
|
||||
You can run your benchmarks in multiple JavaScript runtimes, Tinybench is
|
||||
completely based on the Web APIs with proper timing using `process.hrtime` or
|
||||
`performance.now`.
|
||||
|
||||
- Accurate and precise timing based on the environment
|
||||
- `Event` and `EventTarget` compatible events
|
||||
- Statistically analyzed values
|
||||
- Calculated Percentiles
|
||||
- Fully detailed results
|
||||
- No dependencies
|
||||
|
||||
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
|
||||
|
||||
## Installing
|
||||
|
||||
```bash
|
||||
$ npm install -D tinybench
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
You can start benchmarking by instantiating the `Bench` class and adding
|
||||
benchmark tasks to it.
|
||||
|
||||
```js
|
||||
import { Bench } from 'tinybench';
|
||||
|
||||
const bench = new Bench({ time: 100 });
|
||||
|
||||
bench
|
||||
.add('faster task', () => {
|
||||
console.log('I am faster')
|
||||
})
|
||||
.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.table());
|
||||
|
||||
// Output:
|
||||
// ┌─────────┬───────────────┬──────────┬────────────────────┬───────────┬─────────┐
|
||||
// │ (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' │
|
||||
// └─────────┴───────────────────────┘
|
||||
```
|
||||
|
||||
The `add` method accepts a task name and a task function, so it can benchmark
|
||||
it! This method returns a reference to the Bench instance, so it's possible to
|
||||
use it to create an another task for that instance.
|
||||
|
||||
Note that the task name should always be unique in an instance, because Tinybench stores the tasks based
|
||||
on their names in a `Map`.
|
||||
|
||||
Also note that `tinybench` does not log any result by default. You can extract the relevant stats
|
||||
from `bench.tasks` or any other API after running the benchmark, and process them however you want.
|
||||
|
||||
## Docs
|
||||
|
||||
### `Bench`
|
||||
|
||||
The Benchmark instance for keeping track of the benchmark tasks and controlling
|
||||
them.
|
||||
|
||||
Options:
|
||||
|
||||
```ts
|
||||
export type Options = {
|
||||
/**
|
||||
* time needed for running a benchmark task (milliseconds) @default 500
|
||||
*/
|
||||
time?: number;
|
||||
|
||||
/**
|
||||
* number of times that a task should run if even the time option is finished @default 10
|
||||
*/
|
||||
iterations?: number;
|
||||
|
||||
/**
|
||||
* function to get the current timestamp in milliseconds
|
||||
*/
|
||||
now?: () => number;
|
||||
|
||||
/**
|
||||
* An AbortSignal for aborting the benchmark
|
||||
*/
|
||||
signal?: AbortSignal;
|
||||
|
||||
/**
|
||||
* warmup time (milliseconds) @default 100ms
|
||||
*/
|
||||
warmupTime?: number;
|
||||
|
||||
/**
|
||||
* warmup iterations @default 5
|
||||
*/
|
||||
warmupIterations?: number;
|
||||
|
||||
/**
|
||||
* setup function to run before each benchmark task (cycle)
|
||||
*/
|
||||
setup?: Hook;
|
||||
|
||||
/**
|
||||
* teardown function to run after each benchmark task (cycle)
|
||||
*/
|
||||
teardown?: Hook;
|
||||
};
|
||||
|
||||
export type Hook = (task: Task, mode: "warmup" | "run") => void | Promise<void>;
|
||||
```
|
||||
|
||||
- `async run()`: run the added tasks that were registered using the `add` method
|
||||
- `async warmup()`: warm up the benchmark tasks
|
||||
- `reset()`: reset each task and remove its result
|
||||
- `add(name: string, fn: Fn, opts?: FnOpts)`: add a benchmark task to the task map
|
||||
- `Fn`: `() => any | Promise<any>`
|
||||
- `FnOpts`: `{}`: a set of optional functions run during the benchmark lifecycle that can be used to set up or tear down test data or fixtures without affecting the timing of each task
|
||||
- `beforeAll?: () => any | Promise<any>`: invoked once before iterations of `fn` begin
|
||||
- `beforeEach?: () => any | Promise<any>`: invoked before each time `fn` is executed
|
||||
- `afterEach?: () => any | Promise<any>`: invoked after each time `fn` is executed
|
||||
- `afterAll?: () => any | Promise<any>`: invoked once after all iterations of `fn` have finished
|
||||
- `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
|
||||
|
||||
### `Task`
|
||||
|
||||
A class that represents each benchmark task in Tinybench. It keeps track of the
|
||||
results, name, Bench instance, the task function and the number of times the task
|
||||
function has been executed.
|
||||
|
||||
- `constructor(bench: Bench, name: string, fn: Fn, opts: FnOptions = {})`
|
||||
- `bench: Bench`
|
||||
- `name: string`: task name
|
||||
- `fn: Fn`: the task function
|
||||
- `opts: FnOptions`: Task options
|
||||
- `runs: number`: the number of times the task function has been executed
|
||||
- `result?: TaskResult`: the result object
|
||||
- `async run()`: run the current task and write the results in `Task.result` object
|
||||
- `async warmup()`: warm up the current task
|
||||
- `setResult(result: Partial<TaskResult>)`: change the result object values
|
||||
- `reset()`: reset the task to make the `Task.runs` a zero-value and remove the `Task.result` object
|
||||
|
||||
```ts
|
||||
export interface FnOptions {
|
||||
/**
|
||||
* An optional function that is run before iterations of this task begin
|
||||
*/
|
||||
beforeAll?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run before each iteration of this task
|
||||
*/
|
||||
beforeEach?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run after each iteration of this task
|
||||
*/
|
||||
afterEach?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run after all iterations of this task end
|
||||
*/
|
||||
afterAll?: (this: Task) => void | Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
## `TaskResult`
|
||||
|
||||
the benchmark task result object.
|
||||
|
||||
```ts
|
||||
export type TaskResult = {
|
||||
|
||||
/*
|
||||
* the last error that was thrown while running the task
|
||||
*/
|
||||
error?: unknown;
|
||||
|
||||
/**
|
||||
* The amount of time in milliseconds to run the benchmark task (cycle).
|
||||
*/
|
||||
totalTime: number;
|
||||
|
||||
/**
|
||||
* the minimum value in the samples
|
||||
*/
|
||||
min: number;
|
||||
/**
|
||||
* the maximum value in the samples
|
||||
*/
|
||||
max: number;
|
||||
|
||||
/**
|
||||
* the number of operations per second
|
||||
*/
|
||||
hz: number;
|
||||
|
||||
/**
|
||||
* how long each operation takes (ms)
|
||||
*/
|
||||
period: number;
|
||||
|
||||
/**
|
||||
* task samples of each task iteration time (ms)
|
||||
*/
|
||||
samples: number[];
|
||||
|
||||
/**
|
||||
* samples mean/average (estimate of the population mean)
|
||||
*/
|
||||
mean: number;
|
||||
|
||||
/**
|
||||
* samples variance (estimate of the population variance)
|
||||
*/
|
||||
variance: number;
|
||||
|
||||
/**
|
||||
* samples standard deviation (estimate of the population standard deviation)
|
||||
*/
|
||||
sd: number;
|
||||
|
||||
/**
|
||||
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
|
||||
*/
|
||||
sem: number;
|
||||
|
||||
/**
|
||||
* degrees of freedom
|
||||
*/
|
||||
df: number;
|
||||
|
||||
/**
|
||||
* critical value of the samples
|
||||
*/
|
||||
critical: number;
|
||||
|
||||
/**
|
||||
* margin of error
|
||||
*/
|
||||
moe: number;
|
||||
|
||||
/**
|
||||
* relative margin of error
|
||||
*/
|
||||
rme: number;
|
||||
|
||||
/**
|
||||
* p75 percentile
|
||||
*/
|
||||
p75: number;
|
||||
|
||||
/**
|
||||
* p99 percentile
|
||||
*/
|
||||
p99: number;
|
||||
|
||||
/**
|
||||
* p995 percentile
|
||||
*/
|
||||
p995: number;
|
||||
|
||||
/**
|
||||
* p999 percentile
|
||||
*/
|
||||
p999: number;
|
||||
};
|
||||
```
|
||||
|
||||
### `Events`
|
||||
|
||||
Both the `Task` and `Bench` objects extend the `EventTarget` object, so you can attach listeners to different types of events
|
||||
in each class instance using the universal `addEventListener` and
|
||||
`removeEventListener`.
|
||||
|
||||
```ts
|
||||
/**
|
||||
* Bench events
|
||||
*/
|
||||
export type BenchEvents =
|
||||
| "abort" // when a signal aborts
|
||||
| "complete" // when running a benchmark finishes
|
||||
| "error" // when the benchmark task throws
|
||||
| "reset" // when the reset function gets called
|
||||
| "start" // when running the benchmarks gets started
|
||||
| "warmup" // when the benchmarks start getting warmed up (before start)
|
||||
| "cycle" // when running each benchmark task gets done (cycle)
|
||||
| "add" // when a Task gets added to the Bench
|
||||
| "remove" // when a Task gets removed of the Bench
|
||||
| "todo"; // when a todo Task gets added to the Bench
|
||||
|
||||
/**
|
||||
* task events
|
||||
*/
|
||||
export type TaskEvents =
|
||||
| "abort"
|
||||
| "complete"
|
||||
| "error"
|
||||
| "reset"
|
||||
| "start"
|
||||
| "warmup"
|
||||
| "cycle";
|
||||
```
|
||||
|
||||
For instance:
|
||||
|
||||
```js
|
||||
// runs on each benchmark task's cycle
|
||||
bench.addEventListener("cycle", (e) => {
|
||||
const task = e.task!;
|
||||
});
|
||||
|
||||
// runs only on this benchmark task's cycle
|
||||
task.addEventListener("cycle", (e) => {
|
||||
const task = e.task!;
|
||||
});
|
||||
```
|
||||
|
||||
### `BenchEvent`
|
||||
|
||||
```ts
|
||||
export type BenchEvent = Event & {
|
||||
task: Task | null;
|
||||
};
|
||||
```
|
||||
|
||||
## Prior art
|
||||
|
||||
- [Benchmark.js](https://github.com/bestiejs/benchmark.js)
|
||||
- [Mitata](https://github.com/evanwashere/mitata/)
|
||||
- [Bema](https://github.com/prisma-labs/bema)
|
||||
|
||||
## Authors
|
||||
|
||||
| <a href="https://github.com/Aslemammad"> <img width='150' src="https://avatars.githubusercontent.com/u/37929992?v=4" /><br> Mohammad Bagher </a> |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
|
||||
## Credits
|
||||
|
||||
| <a href="https://github.com/uzploak"> <img width='150' src="https://avatars.githubusercontent.com/u/5059100?v=4" /><br> Uzlopak </a> | <a href="https://github.com/poyoho"> <img width='150' src="https://avatars.githubusercontent.com/u/36070057?v=4" /><br> poyoho </a> |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
|
||||
|
||||
## Contributing
|
||||
|
||||
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>
|
||||
346
node_modules/tinybench/dist/index.cjs
generated
vendored
Normal file
346
node_modules/tinybench/dist/index.cjs
generated
vendored
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
"use strict";
|
||||
var f = Object.defineProperty;
|
||||
var S = Object.getOwnPropertyDescriptor;
|
||||
var H = Object.getOwnPropertyNames;
|
||||
var z = Object.prototype.hasOwnProperty;
|
||||
var P = (n, i, t) => i in n ? f(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
|
||||
var j = (n, i) => {
|
||||
for (var t in i)
|
||||
f(n, t, { get: i[t], enumerable: !0 });
|
||||
}, q = (n, i, t, e) => {
|
||||
if (i && typeof i == "object" || typeof i == "function")
|
||||
for (let s of H(i))
|
||||
!z.call(n, s) && s !== t && f(n, s, { get: () => i[s], enumerable: !(e = S(i, s)) || e.enumerable });
|
||||
return n;
|
||||
};
|
||||
var N = (n) => q(f({}, "__esModule", { value: !0 }), n);
|
||||
var r = (n, i, t) => (P(n, typeof i != "symbol" ? i + "" : i, t), t);
|
||||
|
||||
// src/index.ts
|
||||
var G = {};
|
||||
j(G, {
|
||||
Bench: () => u,
|
||||
Task: () => p,
|
||||
default: () => D,
|
||||
now: () => E
|
||||
});
|
||||
module.exports = N(G);
|
||||
|
||||
// src/event.ts
|
||||
function a(n, i = null) {
|
||||
let t = new Event(n);
|
||||
return Object.defineProperty(t, "task", {
|
||||
value: i,
|
||||
enumerable: !0,
|
||||
writable: !1,
|
||||
configurable: !1
|
||||
}), t;
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var V = {
|
||||
1: 12.71,
|
||||
2: 4.303,
|
||||
3: 3.182,
|
||||
4: 2.776,
|
||||
5: 2.571,
|
||||
6: 2.447,
|
||||
7: 2.365,
|
||||
8: 2.306,
|
||||
9: 2.262,
|
||||
10: 2.228,
|
||||
11: 2.201,
|
||||
12: 2.179,
|
||||
13: 2.16,
|
||||
14: 2.145,
|
||||
15: 2.131,
|
||||
16: 2.12,
|
||||
17: 2.11,
|
||||
18: 2.101,
|
||||
19: 2.093,
|
||||
20: 2.086,
|
||||
21: 2.08,
|
||||
22: 2.074,
|
||||
23: 2.069,
|
||||
24: 2.064,
|
||||
25: 2.06,
|
||||
26: 2.056,
|
||||
27: 2.052,
|
||||
28: 2.048,
|
||||
29: 2.045,
|
||||
30: 2.042,
|
||||
31: 2.0399,
|
||||
32: 2.0378,
|
||||
33: 2.0357,
|
||||
34: 2.0336,
|
||||
35: 2.0315,
|
||||
36: 2.0294,
|
||||
37: 2.0273,
|
||||
38: 2.0252,
|
||||
39: 2.0231,
|
||||
40: 2.021,
|
||||
41: 2.0198,
|
||||
42: 2.0186,
|
||||
43: 2.0174,
|
||||
44: 2.0162,
|
||||
45: 2.015,
|
||||
46: 2.0138,
|
||||
47: 2.0126,
|
||||
48: 2.0114,
|
||||
49: 2.0102,
|
||||
50: 2.009,
|
||||
51: 2.0081,
|
||||
52: 2.0072,
|
||||
53: 2.0063,
|
||||
54: 2.0054,
|
||||
55: 2.0045,
|
||||
56: 2.0036,
|
||||
57: 2.0027,
|
||||
58: 2.0018,
|
||||
59: 2.0009,
|
||||
60: 2,
|
||||
61: 1.9995,
|
||||
62: 1.999,
|
||||
63: 1.9985,
|
||||
64: 1.998,
|
||||
65: 1.9975,
|
||||
66: 1.997,
|
||||
67: 1.9965,
|
||||
68: 1.996,
|
||||
69: 1.9955,
|
||||
70: 1.995,
|
||||
71: 1.9945,
|
||||
72: 1.994,
|
||||
73: 1.9935,
|
||||
74: 1.993,
|
||||
75: 1.9925,
|
||||
76: 1.992,
|
||||
77: 1.9915,
|
||||
78: 1.991,
|
||||
79: 1.9905,
|
||||
80: 1.99,
|
||||
81: 1.9897,
|
||||
82: 1.9894,
|
||||
83: 1.9891,
|
||||
84: 1.9888,
|
||||
85: 1.9885,
|
||||
86: 1.9882,
|
||||
87: 1.9879,
|
||||
88: 1.9876,
|
||||
89: 1.9873,
|
||||
90: 1.987,
|
||||
91: 1.9867,
|
||||
92: 1.9864,
|
||||
93: 1.9861,
|
||||
94: 1.9858,
|
||||
95: 1.9855,
|
||||
96: 1.9852,
|
||||
97: 1.9849,
|
||||
98: 1.9846,
|
||||
99: 1.9843,
|
||||
100: 1.984,
|
||||
101: 1.9838,
|
||||
102: 1.9836,
|
||||
103: 1.9834,
|
||||
104: 1.9832,
|
||||
105: 1.983,
|
||||
106: 1.9828,
|
||||
107: 1.9826,
|
||||
108: 1.9824,
|
||||
109: 1.9822,
|
||||
110: 1.982,
|
||||
111: 1.9818,
|
||||
112: 1.9816,
|
||||
113: 1.9814,
|
||||
114: 1.9812,
|
||||
115: 1.9819,
|
||||
116: 1.9808,
|
||||
117: 1.9806,
|
||||
118: 1.9804,
|
||||
119: 1.9802,
|
||||
120: 1.98,
|
||||
infinity: 1.96
|
||||
}, b = V;
|
||||
|
||||
// src/utils.ts
|
||||
var C = (n) => n / 1e6, E = () => {
|
||||
var n;
|
||||
return typeof ((n = globalThis.process) == null ? void 0 : n.hrtime) == "function" ? C(Number(process.hrtime.bigint())) : performance.now();
|
||||
}, F = (n) => n.reduce((i, t) => i + t, 0) / n.length || 0, B = (n, i) => n.reduce((e, s) => e + (s - i) ** 2) / (n.length - 1) || 0, $ = (async () => {
|
||||
}).constructor, O = (n) => n.constructor === $;
|
||||
|
||||
// src/task.ts
|
||||
var p = class extends EventTarget {
|
||||
constructor(t, e, s, o = {}) {
|
||||
super();
|
||||
r(this, "bench");
|
||||
r(this, "name");
|
||||
r(this, "fn");
|
||||
r(this, "runs", 0);
|
||||
r(this, "result");
|
||||
r(this, "opts");
|
||||
this.bench = t, this.name = e, this.fn = s, this.opts = o;
|
||||
}
|
||||
async run() {
|
||||
var o, l, m;
|
||||
this.dispatchEvent(a("start", this));
|
||||
let t = 0, e = [], s = O(this.fn);
|
||||
for (await this.bench.setup(this, "run"), this.opts.beforeAll != null && await this.opts.beforeAll.call(this); (t < this.bench.time || this.runs < this.bench.iterations) && !((o = this.bench.signal) != null && o.aborted); ) {
|
||||
this.opts.beforeEach != null && await this.opts.beforeEach.call(this);
|
||||
let h = 0;
|
||||
try {
|
||||
h = this.bench.now(), s ? await this.fn() : this.fn();
|
||||
} catch (v) {
|
||||
this.setResult({ error: v });
|
||||
}
|
||||
let c = this.bench.now() - h;
|
||||
this.runs += 1, e.push(c), t += c, this.opts.afterEach != null && await this.opts.afterEach.call(this);
|
||||
}
|
||||
this.opts.afterAll != null && await this.opts.afterAll.call(this), await this.bench.teardown(this, "run"), e.sort((h, c) => h - c);
|
||||
{
|
||||
let h = e[0], c = e[e.length - 1], v = t / this.runs, L = 1e3 / v, w = F(e), g = B(e, w), T = Math.sqrt(g), k = T / Math.sqrt(e.length), y = e.length - 1, x = b[String(Math.round(y) || 1)] || b.infinity, M = k * x, A = M / w * 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 ((l = this.bench.signal) != null && l.aborted)
|
||||
return this;
|
||||
this.setResult({
|
||||
totalTime: t,
|
||||
min: h,
|
||||
max: c,
|
||||
hz: L,
|
||||
period: v,
|
||||
samples: e,
|
||||
mean: w,
|
||||
variance: g,
|
||||
sd: T,
|
||||
sem: k,
|
||||
df: y,
|
||||
critical: x,
|
||||
moe: M,
|
||||
rme: A,
|
||||
p75: K,
|
||||
p99: _,
|
||||
p995: R,
|
||||
p999: I
|
||||
});
|
||||
}
|
||||
return (m = this.result) != null && m.error && (this.dispatchEvent(a("error", this)), this.bench.dispatchEvent(a("error", this))), this.dispatchEvent(a("cycle", this)), this.bench.dispatchEvent(a("cycle", this)), this.dispatchEvent(a("complete", this)), this;
|
||||
}
|
||||
async warmup() {
|
||||
var s;
|
||||
this.dispatchEvent(a("warmup", this));
|
||||
let t = this.bench.now(), e = 0;
|
||||
for (await this.bench.setup(this, "warmup"); (e < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((s = this.bench.signal) != null && s.aborted); ) {
|
||||
try {
|
||||
await Promise.resolve().then(this.fn);
|
||||
} catch (o) {
|
||||
}
|
||||
this.runs += 1, e = this.bench.now() - t;
|
||||
}
|
||||
this.bench.teardown(this, "warmup"), this.runs = 0;
|
||||
}
|
||||
addEventListener(t, e, s) {
|
||||
super.addEventListener(t, e, s);
|
||||
}
|
||||
removeEventListener(t, e, s) {
|
||||
super.removeEventListener(t, e, s);
|
||||
}
|
||||
setResult(t) {
|
||||
this.result = { ...this.result, ...t }, Object.freeze(this.reset);
|
||||
}
|
||||
reset() {
|
||||
this.dispatchEvent(a("reset", this)), this.runs = 0, this.result = void 0;
|
||||
}
|
||||
};
|
||||
|
||||
// src/bench.ts
|
||||
var u = class extends EventTarget {
|
||||
constructor(t = {}) {
|
||||
var e, s, o, l, m, h, c;
|
||||
super();
|
||||
r(this, "_tasks", /* @__PURE__ */ new Map());
|
||||
r(this, "_todos", /* @__PURE__ */ new Map());
|
||||
r(this, "signal");
|
||||
r(this, "warmupTime", 100);
|
||||
r(this, "warmupIterations", 5);
|
||||
r(this, "time", 500);
|
||||
r(this, "iterations", 10);
|
||||
r(this, "now", E);
|
||||
r(this, "setup");
|
||||
r(this, "teardown");
|
||||
this.now = (e = t.now) != null ? e : this.now, this.warmupTime = (s = t.warmupTime) != null ? s : this.warmupTime, this.warmupIterations = (o = t.warmupIterations) != null ? o : this.warmupIterations, this.time = (l = t.time) != null ? l : this.time, this.iterations = (m = t.iterations) != null ? m : this.iterations, this.signal = t.signal, this.setup = (h = t.setup) != null ? h : () => {
|
||||
}, this.teardown = (c = t.teardown) != null ? c : () => {
|
||||
}, this.signal && this.signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
this.dispatchEvent(a("abort"));
|
||||
},
|
||||
{ once: !0 }
|
||||
);
|
||||
}
|
||||
async run() {
|
||||
var e;
|
||||
this.dispatchEvent(a("start"));
|
||||
let t = [];
|
||||
for (let s of [...this._tasks.values()])
|
||||
(e = this.signal) != null && e.aborted ? t.push(s) : t.push(await s.run());
|
||||
return this.dispatchEvent(a("complete")), t;
|
||||
}
|
||||
async warmup() {
|
||||
this.dispatchEvent(a("warmup"));
|
||||
for (let [, t] of this._tasks)
|
||||
await t.warmup();
|
||||
}
|
||||
reset() {
|
||||
this.dispatchEvent(a("reset")), this._tasks.forEach((t) => {
|
||||
t.reset();
|
||||
});
|
||||
}
|
||||
add(t, e, s = {}) {
|
||||
let o = new p(this, t, e, s);
|
||||
return this._tasks.set(t, o), this.dispatchEvent(a("add", o)), this;
|
||||
}
|
||||
todo(t, e = () => {
|
||||
}, s = {}) {
|
||||
let o = new p(this, t, e, s);
|
||||
return this._todos.set(t, o), this.dispatchEvent(a("todo", o)), this;
|
||||
}
|
||||
remove(t) {
|
||||
let e = this.getTask(t);
|
||||
return this.dispatchEvent(a("remove", e)), this._tasks.delete(t), this;
|
||||
}
|
||||
addEventListener(t, e, s) {
|
||||
super.addEventListener(t, e, s);
|
||||
}
|
||||
removeEventListener(t, e, s) {
|
||||
super.removeEventListener(t, e, s);
|
||||
}
|
||||
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() {
|
||||
return [...this._tasks.values()].map((t) => t.result);
|
||||
}
|
||||
get tasks() {
|
||||
return [...this._tasks.values()];
|
||||
}
|
||||
get todos() {
|
||||
return [...this._todos.values()];
|
||||
}
|
||||
getTask(t) {
|
||||
return this._tasks.get(t);
|
||||
}
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var D = u;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Bench,
|
||||
Task,
|
||||
now
|
||||
});
|
||||
349
node_modules/tinybench/dist/index.d.ts
generated
vendored
Normal file
349
node_modules/tinybench/dist/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
/**
|
||||
* A class that represents each benchmark task in Tinybench. It keeps track of the
|
||||
* results, name, Bench instance, the task function and the number times the task
|
||||
* function has been executed.
|
||||
*/
|
||||
declare class Task extends EventTarget {
|
||||
bench: Bench;
|
||||
/**
|
||||
* task name
|
||||
*/
|
||||
name: string;
|
||||
fn: Fn;
|
||||
runs: number;
|
||||
/**
|
||||
* the result object
|
||||
*/
|
||||
result?: TaskResult;
|
||||
/**
|
||||
* Task options
|
||||
*/
|
||||
opts: FnOptions;
|
||||
constructor(bench: Bench, name: string, fn: Fn, opts?: FnOptions);
|
||||
/**
|
||||
* run the current task and write the results in `Task.result` object
|
||||
*/
|
||||
run(): Promise<this>;
|
||||
/**
|
||||
* warmup the current task
|
||||
*/
|
||||
warmup(): Promise<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;
|
||||
/**
|
||||
* change the result object values
|
||||
*/
|
||||
setResult(result: Partial<TaskResult>): void;
|
||||
/**
|
||||
* reset the task to make the `Task.runs` a zero-value and remove the `Task.result`
|
||||
* object
|
||||
*/
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* the task function
|
||||
*/
|
||||
type Fn = () => any | Promise<any>;
|
||||
|
||||
interface FnOptions {
|
||||
/**
|
||||
* An optional function that is run before iterations of this task begin
|
||||
*/
|
||||
beforeAll?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run before each iteration of this task
|
||||
*/
|
||||
beforeEach?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run after each iteration of this task
|
||||
*/
|
||||
afterEach?: (this: Task) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* An optional function that is run after all iterations of this task end
|
||||
*/
|
||||
afterAll?: (this: Task) => void | Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* the benchmark task result object
|
||||
*/
|
||||
type TaskResult = {
|
||||
/*
|
||||
* the last error that was thrown while running the task
|
||||
*/
|
||||
error?: unknown;
|
||||
|
||||
/**
|
||||
* The amount of time in milliseconds to run the benchmark task (cycle).
|
||||
*/
|
||||
totalTime: number;
|
||||
|
||||
/**
|
||||
* the minimum value in the samples
|
||||
*/
|
||||
min: number;
|
||||
/**
|
||||
* the maximum value in the samples
|
||||
*/
|
||||
max: number;
|
||||
|
||||
/**
|
||||
* the number of operations per second
|
||||
*/
|
||||
hz: number;
|
||||
|
||||
/**
|
||||
* how long each operation takes (ms)
|
||||
*/
|
||||
period: number;
|
||||
|
||||
/**
|
||||
* task samples of each task iteration time (ms)
|
||||
*/
|
||||
samples: number[];
|
||||
|
||||
/**
|
||||
* samples mean/average (estimate of the population mean)
|
||||
*/
|
||||
mean: number;
|
||||
|
||||
/**
|
||||
* samples variance (estimate of the population variance)
|
||||
*/
|
||||
variance: number;
|
||||
|
||||
/**
|
||||
* samples standard deviation (estimate of the population standard deviation)
|
||||
*/
|
||||
sd: number;
|
||||
|
||||
/**
|
||||
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
|
||||
*/
|
||||
sem: number;
|
||||
|
||||
/**
|
||||
* degrees of freedom
|
||||
*/
|
||||
df: number;
|
||||
|
||||
/**
|
||||
* critical value of the samples
|
||||
*/
|
||||
critical: number;
|
||||
|
||||
/**
|
||||
* margin of error
|
||||
*/
|
||||
moe: number;
|
||||
|
||||
/**
|
||||
* relative margin of error
|
||||
*/
|
||||
rme: number;
|
||||
|
||||
/**
|
||||
* p75 percentile
|
||||
*/
|
||||
p75: number;
|
||||
|
||||
/**
|
||||
* p99 percentile
|
||||
*/
|
||||
p99: number;
|
||||
|
||||
/**
|
||||
* p995 percentile
|
||||
*/
|
||||
p995: number;
|
||||
|
||||
/**
|
||||
* p999 percentile
|
||||
*/
|
||||
p999: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Both the `Task` and `Bench` objects extend the `EventTarget` object,
|
||||
* so you can attach a listeners to different types of events
|
||||
* to each class instance using the universal `addEventListener` and
|
||||
* `removeEventListener`
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bench events
|
||||
*/
|
||||
type BenchEvents =
|
||||
| 'abort' // when a signal aborts
|
||||
| 'complete' // when running a benchmark finishes
|
||||
| 'error' // when the benchmark task throws
|
||||
| 'reset' // when the reset function gets called
|
||||
| 'start' // when running the benchmarks gets started
|
||||
| 'warmup' // when the benchmarks start getting warmed up (before start)
|
||||
| 'cycle' // when running each benchmark task gets done (cycle)
|
||||
| 'add' // when a Task gets added to the Bench
|
||||
| 'remove' // when a Task gets removed of the Bench
|
||||
| 'todo'; // when a todo Task gets added to the Bench
|
||||
|
||||
type Hook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;
|
||||
|
||||
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
|
||||
todo: TaskEventListener
|
||||
}
|
||||
|
||||
/**
|
||||
* task events
|
||||
*/
|
||||
type TaskEvents =
|
||||
| 'abort'
|
||||
| 'complete'
|
||||
| 'error'
|
||||
| 'reset'
|
||||
| 'start'
|
||||
| 'warmup'
|
||||
| 'cycle';
|
||||
|
||||
type TaskEventsMap = {
|
||||
abort: NoopEventListener
|
||||
start: TaskEventListener
|
||||
error: TaskEventListener
|
||||
cycle: TaskEventListener
|
||||
complete: TaskEventListener
|
||||
warmup: TaskEventListener
|
||||
reset: TaskEventListener
|
||||
}
|
||||
type Options = {
|
||||
/**
|
||||
* time needed for running a benchmark task (milliseconds) @default 500
|
||||
*/
|
||||
time?: number;
|
||||
|
||||
/**
|
||||
* number of times that a task should run if even the time option is finished @default 10
|
||||
*/
|
||||
iterations?: number;
|
||||
|
||||
/**
|
||||
* function to get the current timestamp in milliseconds
|
||||
*/
|
||||
now?: () => number;
|
||||
|
||||
/**
|
||||
* An AbortSignal for aborting the benchmark
|
||||
*/
|
||||
signal?: AbortSignal;
|
||||
|
||||
/**
|
||||
* warmup time (milliseconds) @default 100ms
|
||||
*/
|
||||
warmupTime?: number;
|
||||
|
||||
/**
|
||||
* warmup iterations @default 5
|
||||
*/
|
||||
warmupIterations?: number;
|
||||
|
||||
/**
|
||||
* setup function to run before each benchmark task (cycle)
|
||||
*/
|
||||
setup?: Hook;
|
||||
|
||||
/**
|
||||
* teardown function to run after each benchmark task (cycle)
|
||||
*/
|
||||
teardown?: Hook;
|
||||
};
|
||||
|
||||
type BenchEvent = Event & {
|
||||
task: Task | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Benchmark instance for keeping track of the benchmark tasks and controlling
|
||||
* them.
|
||||
*/
|
||||
declare class Bench extends EventTarget {
|
||||
_tasks: Map<string, Task>;
|
||||
_todos: Map<string, Task>;
|
||||
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
|
||||
* {@link add} method.
|
||||
* Note: This method does not do any warmup. Call {@link warmup} for that.
|
||||
*/
|
||||
run(): Promise<Task[]>;
|
||||
/**
|
||||
* warmup the benchmark tasks.
|
||||
* This is not run by default by the {@link run} method.
|
||||
*/
|
||||
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, opts?: FnOptions): this;
|
||||
/**
|
||||
* add a benchmark todo to the todo map
|
||||
*/
|
||||
todo(name: string, fn?: Fn, opts?: FnOptions): 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;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
get results(): (TaskResult | undefined)[];
|
||||
/**
|
||||
* (getter) tasks as an array
|
||||
*/
|
||||
get tasks(): Task[];
|
||||
get todos(): 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 };
|
||||
322
node_modules/tinybench/dist/index.js
generated
vendored
Normal file
322
node_modules/tinybench/dist/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
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);
|
||||
|
||||
// src/event.ts
|
||||
function r(n, a = null) {
|
||||
let t = new Event(n);
|
||||
return Object.defineProperty(t, "task", {
|
||||
value: a,
|
||||
enumerable: !0,
|
||||
writable: !1,
|
||||
configurable: !1
|
||||
}), t;
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var z = {
|
||||
1: 12.71,
|
||||
2: 4.303,
|
||||
3: 3.182,
|
||||
4: 2.776,
|
||||
5: 2.571,
|
||||
6: 2.447,
|
||||
7: 2.365,
|
||||
8: 2.306,
|
||||
9: 2.262,
|
||||
10: 2.228,
|
||||
11: 2.201,
|
||||
12: 2.179,
|
||||
13: 2.16,
|
||||
14: 2.145,
|
||||
15: 2.131,
|
||||
16: 2.12,
|
||||
17: 2.11,
|
||||
18: 2.101,
|
||||
19: 2.093,
|
||||
20: 2.086,
|
||||
21: 2.08,
|
||||
22: 2.074,
|
||||
23: 2.069,
|
||||
24: 2.064,
|
||||
25: 2.06,
|
||||
26: 2.056,
|
||||
27: 2.052,
|
||||
28: 2.048,
|
||||
29: 2.045,
|
||||
30: 2.042,
|
||||
31: 2.0399,
|
||||
32: 2.0378,
|
||||
33: 2.0357,
|
||||
34: 2.0336,
|
||||
35: 2.0315,
|
||||
36: 2.0294,
|
||||
37: 2.0273,
|
||||
38: 2.0252,
|
||||
39: 2.0231,
|
||||
40: 2.021,
|
||||
41: 2.0198,
|
||||
42: 2.0186,
|
||||
43: 2.0174,
|
||||
44: 2.0162,
|
||||
45: 2.015,
|
||||
46: 2.0138,
|
||||
47: 2.0126,
|
||||
48: 2.0114,
|
||||
49: 2.0102,
|
||||
50: 2.009,
|
||||
51: 2.0081,
|
||||
52: 2.0072,
|
||||
53: 2.0063,
|
||||
54: 2.0054,
|
||||
55: 2.0045,
|
||||
56: 2.0036,
|
||||
57: 2.0027,
|
||||
58: 2.0018,
|
||||
59: 2.0009,
|
||||
60: 2,
|
||||
61: 1.9995,
|
||||
62: 1.999,
|
||||
63: 1.9985,
|
||||
64: 1.998,
|
||||
65: 1.9975,
|
||||
66: 1.997,
|
||||
67: 1.9965,
|
||||
68: 1.996,
|
||||
69: 1.9955,
|
||||
70: 1.995,
|
||||
71: 1.9945,
|
||||
72: 1.994,
|
||||
73: 1.9935,
|
||||
74: 1.993,
|
||||
75: 1.9925,
|
||||
76: 1.992,
|
||||
77: 1.9915,
|
||||
78: 1.991,
|
||||
79: 1.9905,
|
||||
80: 1.99,
|
||||
81: 1.9897,
|
||||
82: 1.9894,
|
||||
83: 1.9891,
|
||||
84: 1.9888,
|
||||
85: 1.9885,
|
||||
86: 1.9882,
|
||||
87: 1.9879,
|
||||
88: 1.9876,
|
||||
89: 1.9873,
|
||||
90: 1.987,
|
||||
91: 1.9867,
|
||||
92: 1.9864,
|
||||
93: 1.9861,
|
||||
94: 1.9858,
|
||||
95: 1.9855,
|
||||
96: 1.9852,
|
||||
97: 1.9849,
|
||||
98: 1.9846,
|
||||
99: 1.9843,
|
||||
100: 1.984,
|
||||
101: 1.9838,
|
||||
102: 1.9836,
|
||||
103: 1.9834,
|
||||
104: 1.9832,
|
||||
105: 1.983,
|
||||
106: 1.9828,
|
||||
107: 1.9826,
|
||||
108: 1.9824,
|
||||
109: 1.9822,
|
||||
110: 1.982,
|
||||
111: 1.9818,
|
||||
112: 1.9816,
|
||||
113: 1.9814,
|
||||
114: 1.9812,
|
||||
115: 1.9819,
|
||||
116: 1.9808,
|
||||
117: 1.9806,
|
||||
118: 1.9804,
|
||||
119: 1.9802,
|
||||
120: 1.98,
|
||||
infinity: 1.96
|
||||
}, w = z;
|
||||
|
||||
// src/utils.ts
|
||||
var P = (n) => n / 1e6, b = () => {
|
||||
var n;
|
||||
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;
|
||||
|
||||
// src/task.ts
|
||||
var p = class extends EventTarget {
|
||||
constructor(t, e, s, o = {}) {
|
||||
super();
|
||||
i(this, "bench");
|
||||
i(this, "name");
|
||||
i(this, "fn");
|
||||
i(this, "runs", 0);
|
||||
i(this, "result");
|
||||
i(this, "opts");
|
||||
this.bench = t, this.name = e, this.fn = s, this.opts = o;
|
||||
}
|
||||
async run() {
|
||||
var o, u, l;
|
||||
this.dispatchEvent(r("start", this));
|
||||
let t = 0, e = [], s = O(this.fn);
|
||||
for (await this.bench.setup(this, "run"), this.opts.beforeAll != null && await this.opts.beforeAll.call(this); (t < this.bench.time || this.runs < this.bench.iterations) && !((o = this.bench.signal) != null && o.aborted); ) {
|
||||
this.opts.beforeEach != null && await this.opts.beforeEach.call(this);
|
||||
let h = 0;
|
||||
try {
|
||||
h = this.bench.now(), s ? await this.fn() : this.fn();
|
||||
} catch (f) {
|
||||
this.setResult({ error: f });
|
||||
}
|
||||
let c = this.bench.now() - h;
|
||||
this.runs += 1, e.push(c), t += c, this.opts.afterEach != null && await this.opts.afterEach.call(this);
|
||||
}
|
||||
this.opts.afterAll != null && await this.opts.afterAll.call(this), await this.bench.teardown(this, "run"), e.sort((h, c) => h - c);
|
||||
{
|
||||
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)
|
||||
return this;
|
||||
this.setResult({
|
||||
totalTime: t,
|
||||
min: h,
|
||||
max: c,
|
||||
hz: L,
|
||||
period: f,
|
||||
samples: e,
|
||||
mean: E,
|
||||
variance: g,
|
||||
sd: T,
|
||||
sem: k,
|
||||
df: y,
|
||||
critical: x,
|
||||
moe: M,
|
||||
rme: A,
|
||||
p75: K,
|
||||
p99: _,
|
||||
p995: R,
|
||||
p999: I
|
||||
});
|
||||
}
|
||||
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 s;
|
||||
this.dispatchEvent(r("warmup", this));
|
||||
let t = this.bench.now(), e = 0;
|
||||
for (await this.bench.setup(this, "warmup"); (e < this.bench.warmupTime || this.runs < this.bench.warmupIterations) && !((s = this.bench.signal) != null && s.aborted); ) {
|
||||
try {
|
||||
await Promise.resolve().then(this.fn);
|
||||
} catch (o) {
|
||||
}
|
||||
this.runs += 1, e = this.bench.now() - t;
|
||||
}
|
||||
this.bench.teardown(this, "warmup"), this.runs = 0;
|
||||
}
|
||||
addEventListener(t, e, s) {
|
||||
super.addEventListener(t, e, s);
|
||||
}
|
||||
removeEventListener(t, e, s) {
|
||||
super.removeEventListener(t, e, s);
|
||||
}
|
||||
setResult(t) {
|
||||
this.result = { ...this.result, ...t }, Object.freeze(this.reset);
|
||||
}
|
||||
reset() {
|
||||
this.dispatchEvent(r("reset", this)), this.runs = 0, this.result = void 0;
|
||||
}
|
||||
};
|
||||
|
||||
// src/bench.ts
|
||||
var v = class extends EventTarget {
|
||||
constructor(t = {}) {
|
||||
var e, s, o, u, l, h, c;
|
||||
super();
|
||||
i(this, "_tasks", /* @__PURE__ */ new Map());
|
||||
i(this, "_todos", /* @__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 = (e = t.now) != null ? e : this.now, this.warmupTime = (s = t.warmupTime) != null ? s : this.warmupTime, this.warmupIterations = (o = t.warmupIterations) != null ? o : this.warmupIterations, this.time = (u = t.time) != null ? u : this.time, this.iterations = (l = t.iterations) != null ? l : this.iterations, this.signal = t.signal, this.setup = (h = t.setup) != null ? h : () => {
|
||||
}, this.teardown = (c = t.teardown) != null ? c : () => {
|
||||
}, this.signal && this.signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
this.dispatchEvent(r("abort"));
|
||||
},
|
||||
{ once: !0 }
|
||||
);
|
||||
}
|
||||
async run() {
|
||||
var e;
|
||||
this.dispatchEvent(r("start"));
|
||||
let t = [];
|
||||
for (let s of [...this._tasks.values()])
|
||||
(e = this.signal) != null && e.aborted ? t.push(s) : t.push(await s.run());
|
||||
return this.dispatchEvent(r("complete")), t;
|
||||
}
|
||||
async warmup() {
|
||||
this.dispatchEvent(r("warmup"));
|
||||
for (let [, t] of this._tasks)
|
||||
await t.warmup();
|
||||
}
|
||||
reset() {
|
||||
this.dispatchEvent(r("reset")), this._tasks.forEach((t) => {
|
||||
t.reset();
|
||||
});
|
||||
}
|
||||
add(t, e, s = {}) {
|
||||
let o = new p(this, t, e, s);
|
||||
return this._tasks.set(t, o), this.dispatchEvent(r("add", o)), this;
|
||||
}
|
||||
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) {
|
||||
let e = this.getTask(t);
|
||||
return this.dispatchEvent(r("remove", e)), this._tasks.delete(t), this;
|
||||
}
|
||||
addEventListener(t, e, s) {
|
||||
super.addEventListener(t, e, s);
|
||||
}
|
||||
removeEventListener(t, e, s) {
|
||||
super.removeEventListener(t, e, s);
|
||||
}
|
||||
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() {
|
||||
return [...this._tasks.values()].map((t) => t.result);
|
||||
}
|
||||
get tasks() {
|
||||
return [...this._tasks.values()];
|
||||
}
|
||||
get todos() {
|
||||
return [...this._todos.values()];
|
||||
}
|
||||
getTask(t) {
|
||||
return this._tasks.get(t);
|
||||
}
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var tt = v;
|
||||
export {
|
||||
v as Bench,
|
||||
p as Task,
|
||||
tt as default,
|
||||
b as now
|
||||
};
|
||||
50
node_modules/tinybench/package.json
generated
vendored
Normal file
50
node_modules/tinybench/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "tinybench",
|
||||
"version": "2.5.0",
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@7.5.1",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs",
|
||||
"default": "./dist/index.cjs"
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": "tinylibs/tinybench",
|
||||
"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": [
|
||||
"benchmark",
|
||||
"tinylibs",
|
||||
"tiny"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "tsup --watch",
|
||||
"build": "tsup",
|
||||
"release": "bumpp package.json --commit --push --tag && npm run publish",
|
||||
"test": "vitest --no-threads"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue