mirror of
https://github.com/soconnor0919/beenpad.git
synced 2026-02-05 00:06:40 -05:00
first commit
This commit is contained in:
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.
|
||||
422
node_modules/tinybench/README.md
generated
vendored
Normal file
422
node_modules/tinybench/README.md
generated
vendored
Normal file
@@ -0,0 +1,422 @@
|
||||
_I'm transitioning to a full-time open source career. Your support would be greatly appreciated 🙌_
|
||||
<a href="https://polar.sh/tinylibs/subscriptions"><picture><source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/embed/tiers.svg?org=tinylibs&darkmode"><img alt="Subscription Tiers on Polar" src="https://polar.sh/embed/tiers.svg?org=tinylibs"></picture></a>
|
||||
|
||||
# Tinybench 🔎
|
||||
|
||||
[](https://github.com/tinylibs/tinybench/actions/workflows/test.yml)
|
||||
[](https://www.npmjs.com/package/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.warmup(); // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
|
||||
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.table((task) => ({'Task name': task.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;
|
||||
|
||||
/**
|
||||
* Throw if a task fails (events will not work if true)
|
||||
*/
|
||||
throws?: boolean;
|
||||
|
||||
/**
|
||||
* 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 runConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: similar to the `run` method but runs concurrently rather than sequentially. See the [Concurrency](#Concurrency) section.
|
||||
- `async warmup()`: warm up the benchmark tasks
|
||||
- `async warmupConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: warm up the benchmark tasks concurrently
|
||||
- `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;
|
||||
};
|
||||
```
|
||||
|
||||
### `process.hrtime`
|
||||
if you want more accurate results for nodejs with `process.hrtime`, then import
|
||||
the `hrtimeNow` function from the library and pass it to the `Bench` options.
|
||||
|
||||
```ts
|
||||
import { hrtimeNow } from 'tinybench';
|
||||
```
|
||||
It may make your benchmarks slower, check #42.
|
||||
|
||||
## Concurrency
|
||||
|
||||
- When `mode` is set to `null` (default), concurrency is disabled.
|
||||
- When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
||||
- When `mode` is set to 'bench', different tasks within the bench run concurrently. Concurrent cycles.
|
||||
|
||||
```ts
|
||||
// options way (recommended)
|
||||
bench.threshold = 10 // The maximum number of concurrent tasks to run. Defaults to Infinity.
|
||||
bench.concurrency = "task" // The concurrency mode to determine how tasks are run.
|
||||
// await bench.warmup()
|
||||
await bench.run()
|
||||
|
||||
// standalone method way
|
||||
// await bench.warmupConcurrently(10, "task")
|
||||
await bench.runConcurrently(10, "task") // with runConcurrently, mode is set to 'bench' by default
|
||||
```
|
||||
|
||||
## 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/uzlopak"> <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>
|
||||
585
node_modules/tinybench/dist/index.cjs
generated
vendored
Normal file
585
node_modules/tinybench/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,585 @@
|
||||
"use strict";
|
||||
var x = Object.defineProperty;
|
||||
var G = Object.getOwnPropertyDescriptor;
|
||||
var J = Object.getOwnPropertyNames;
|
||||
var U = Object.prototype.hasOwnProperty;
|
||||
var q = (n) => {
|
||||
throw TypeError(n);
|
||||
};
|
||||
var W = (n, s, t) => s in n ? x(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
|
||||
var X = (n, s) => {
|
||||
for (var t in s)
|
||||
x(n, t, { get: s[t], enumerable: !0 });
|
||||
}, Z = (n, s, t, e) => {
|
||||
if (s && typeof s == "object" || typeof s == "function")
|
||||
for (let r of J(s))
|
||||
!U.call(n, r) && r !== t && x(n, r, { get: () => s[r], enumerable: !(e = G(s, r)) || e.enumerable });
|
||||
return n;
|
||||
};
|
||||
var tt = (n) => Z(x({}, "__esModule", { value: !0 }), n);
|
||||
var M = (n, s, t) => W(n, typeof s != "symbol" ? s + "" : s, t), S = (n, s, t) => s.has(n) || q("Cannot " + t);
|
||||
var d = (n, s, t) => (S(n, s, "read from private field"), t ? t.call(n) : s.get(n)), L = (n, s, t) => s.has(n) ? q("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(n) : s.set(n, t), f = (n, s, t, e) => (S(n, s, "write to private field"), e ? e.call(n, t) : s.set(n, t), t);
|
||||
var N = (n, s, t, e) => ({
|
||||
set _(r) {
|
||||
f(n, s, r, t);
|
||||
},
|
||||
get _() {
|
||||
return d(n, s, e);
|
||||
}
|
||||
});
|
||||
|
||||
// src/index.ts
|
||||
var ot = {};
|
||||
X(ot, {
|
||||
Bench: () => k,
|
||||
Task: () => v,
|
||||
hrtimeNow: () => z,
|
||||
now: () => A
|
||||
});
|
||||
module.exports = tt(ot);
|
||||
|
||||
// node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
||||
var B = class {
|
||||
constructor(s) {
|
||||
M(this, "value");
|
||||
M(this, "next");
|
||||
this.value = s;
|
||||
}
|
||||
}, m, E, b, g = class {
|
||||
constructor() {
|
||||
L(this, m);
|
||||
L(this, E);
|
||||
L(this, b);
|
||||
this.clear();
|
||||
}
|
||||
enqueue(s) {
|
||||
let t = new B(s);
|
||||
d(this, m) ? (d(this, E).next = t, f(this, E, t)) : (f(this, m, t), f(this, E, t)), N(this, b)._++;
|
||||
}
|
||||
dequeue() {
|
||||
let s = d(this, m);
|
||||
if (s)
|
||||
return f(this, m, d(this, m).next), N(this, b)._--, s.value;
|
||||
}
|
||||
clear() {
|
||||
f(this, m, void 0), f(this, E, void 0), f(this, b, 0);
|
||||
}
|
||||
get size() {
|
||||
return d(this, b);
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
let s = d(this, m);
|
||||
for (; s; )
|
||||
yield s.value, s = s.next;
|
||||
}
|
||||
};
|
||||
m = new WeakMap(), E = new WeakMap(), b = new WeakMap();
|
||||
|
||||
// node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
||||
function y(n) {
|
||||
if (!((Number.isInteger(n) || n === Number.POSITIVE_INFINITY) && n > 0))
|
||||
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
||||
let s = new g(), t = 0, e = () => {
|
||||
t--, s.size > 0 && s.dequeue()();
|
||||
}, r = async (h, p, a) => {
|
||||
t++;
|
||||
let l = (async () => h(...a))();
|
||||
p(l);
|
||||
try {
|
||||
await l;
|
||||
} catch (T) {
|
||||
}
|
||||
e();
|
||||
}, i = (h, p, a) => {
|
||||
s.enqueue(r.bind(void 0, h, p, a)), (async () => (await Promise.resolve(), t < n && s.size > 0 && s.dequeue()()))();
|
||||
}, c = (h, ...p) => new Promise((a) => {
|
||||
i(h, a, p);
|
||||
});
|
||||
return Object.defineProperties(c, {
|
||||
activeCount: {
|
||||
get: () => t
|
||||
},
|
||||
pendingCount: {
|
||||
get: () => s.size
|
||||
},
|
||||
clearQueue: {
|
||||
value: () => {
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
}), c;
|
||||
}
|
||||
|
||||
// src/event.ts
|
||||
function o(n, s = null) {
|
||||
let t = new Event(n);
|
||||
return s && Object.defineProperty(t, "task", {
|
||||
value: s,
|
||||
enumerable: !0,
|
||||
writable: !1,
|
||||
configurable: !1
|
||||
}), t;
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var et = {
|
||||
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
|
||||
}, P = et;
|
||||
|
||||
// src/utils.ts
|
||||
var st = (n) => n / 1e6, z = () => st(Number(process.hrtime.bigint())), A = () => performance.now();
|
||||
function nt(n) {
|
||||
return n !== null && typeof n == "object" && typeof n.then == "function";
|
||||
}
|
||||
var j = (n, s) => n.reduce((e, r) => e + (r - s) ** 2, 0) / (n.length - 1) || 0, rt = (async () => {
|
||||
}).constructor, it = (n) => n.constructor === rt, H = async (n) => {
|
||||
if (it(n.fn))
|
||||
return !0;
|
||||
try {
|
||||
if (n.opts.beforeEach != null)
|
||||
try {
|
||||
await n.opts.beforeEach.call(n);
|
||||
} catch (e) {
|
||||
}
|
||||
let s = n.fn(), t = nt(s);
|
||||
if (t)
|
||||
try {
|
||||
await s;
|
||||
} catch (e) {
|
||||
}
|
||||
if (n.opts.afterEach != null)
|
||||
try {
|
||||
await n.opts.afterEach.call(n);
|
||||
} catch (e) {
|
||||
}
|
||||
return t;
|
||||
} catch (s) {
|
||||
return !1;
|
||||
}
|
||||
};
|
||||
|
||||
// src/task.ts
|
||||
var v = class extends EventTarget {
|
||||
constructor(t, e, r, i = {}) {
|
||||
super();
|
||||
/*
|
||||
* the number of times the task
|
||||
* function has been executed
|
||||
*/
|
||||
this.runs = 0;
|
||||
this.bench = t, this.name = e, this.fn = r, this.opts = i;
|
||||
}
|
||||
async loop(t, e) {
|
||||
var T;
|
||||
let r = this.bench.concurrency === "task", { threshold: i } = this.bench, c = 0, h = [];
|
||||
if (this.opts.beforeAll != null)
|
||||
try {
|
||||
await this.opts.beforeAll.call(this);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
let p = await H(this), a = async () => {
|
||||
this.opts.beforeEach != null && await this.opts.beforeEach.call(this);
|
||||
let u = 0;
|
||||
if (p) {
|
||||
let w = this.bench.now();
|
||||
await this.fn.call(this), u = this.bench.now() - w;
|
||||
} else {
|
||||
let w = this.bench.now();
|
||||
this.fn.call(this), u = this.bench.now() - w;
|
||||
}
|
||||
h.push(u), c += u, this.opts.afterEach != null && await this.opts.afterEach.call(this);
|
||||
}, l = y(i);
|
||||
try {
|
||||
let u = [];
|
||||
for (; (c < t || h.length + l.activeCount + l.pendingCount < e) && !((T = this.bench.signal) != null && T.aborted); )
|
||||
r ? u.push(l(a)) : await a();
|
||||
u.length && await Promise.all(u);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
if (this.opts.afterAll != null)
|
||||
try {
|
||||
await this.opts.afterAll.call(this);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
return { samples: h };
|
||||
}
|
||||
/**
|
||||
* run the current task and write the results in `Task.result` object
|
||||
*/
|
||||
async run() {
|
||||
var r, i;
|
||||
if ((r = this.result) != null && r.error)
|
||||
return this;
|
||||
this.dispatchEvent(o("start", this)), await this.bench.setup(this, "run");
|
||||
let { samples: t, error: e } = await this.loop(this.bench.time, this.bench.iterations);
|
||||
if (this.bench.teardown(this, "run"), t) {
|
||||
let c = t.reduce((O, F) => O + F, 0);
|
||||
this.runs = t.length, t.sort((O, F) => O - F);
|
||||
let h = c / this.runs, p = 1e3 / h, a = t.length, l = a - 1, T = t[0], u = t[l], w = c / t.length || 0, R = j(t, w), I = Math.sqrt(R), _ = I / Math.sqrt(a), K = P[String(Math.round(l) || 1)] || P.infinity, C = _ * K, V = C / w * 100, Q = t[Math.ceil(a * 0.75) - 1], Y = t[Math.ceil(a * 0.99) - 1], $ = t[Math.ceil(a * 0.995) - 1], D = t[Math.ceil(a * 0.999) - 1];
|
||||
if ((i = this.bench.signal) != null && i.aborted)
|
||||
return this;
|
||||
this.setResult({
|
||||
totalTime: c,
|
||||
min: T,
|
||||
max: u,
|
||||
hz: p,
|
||||
period: h,
|
||||
samples: t,
|
||||
mean: w,
|
||||
variance: R,
|
||||
sd: I,
|
||||
sem: _,
|
||||
df: l,
|
||||
critical: K,
|
||||
moe: C,
|
||||
rme: V,
|
||||
p75: Q,
|
||||
p99: Y,
|
||||
p995: $,
|
||||
p999: D
|
||||
});
|
||||
}
|
||||
if (e) {
|
||||
if (this.setResult({ error: e }), this.bench.throws)
|
||||
throw e;
|
||||
this.dispatchEvent(o("error", this)), this.bench.dispatchEvent(o("error", this));
|
||||
}
|
||||
return this.dispatchEvent(o("cycle", this)), this.bench.dispatchEvent(o("cycle", this)), this.dispatchEvent(o("complete", this)), this;
|
||||
}
|
||||
/**
|
||||
* warmup the current task
|
||||
*/
|
||||
async warmup() {
|
||||
var e;
|
||||
if ((e = this.result) != null && e.error)
|
||||
return;
|
||||
this.dispatchEvent(o("warmup", this)), await this.bench.setup(this, "warmup");
|
||||
let { error: t } = await this.loop(this.bench.warmupTime, this.bench.warmupIterations);
|
||||
if (this.bench.teardown(this, "warmup"), t && (this.setResult({ error: t }), this.bench.throws))
|
||||
throw t;
|
||||
}
|
||||
addEventListener(t, e, r) {
|
||||
super.addEventListener(t, e, r);
|
||||
}
|
||||
removeEventListener(t, e, r) {
|
||||
super.removeEventListener(t, e, r);
|
||||
}
|
||||
/**
|
||||
* change the result object values
|
||||
*/
|
||||
setResult(t) {
|
||||
this.result = { ...this.result, ...t }, Object.freeze(this.result);
|
||||
}
|
||||
/**
|
||||
* reset the task to make the `Task.runs` a zero-value and remove the `Task.result`
|
||||
* object
|
||||
*/
|
||||
reset() {
|
||||
this.dispatchEvent(o("reset", this)), this.runs = 0, this.result = void 0;
|
||||
}
|
||||
};
|
||||
|
||||
// src/bench.ts
|
||||
var k = class extends EventTarget {
|
||||
constructor(t = {}) {
|
||||
var e, r, i, c, h, p, a, l;
|
||||
super();
|
||||
/*
|
||||
* @private the task map
|
||||
*/
|
||||
this._tasks = /* @__PURE__ */ new Map();
|
||||
this._todos = /* @__PURE__ */ new Map();
|
||||
/**
|
||||
* Executes tasks concurrently based on the specified concurrency mode.
|
||||
*
|
||||
* - When `mode` is set to `null` (default), concurrency is disabled.
|
||||
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
||||
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
||||
*/
|
||||
this.concurrency = null;
|
||||
/**
|
||||
* The maximum number of concurrent tasks to run. Defaults to Infinity.
|
||||
*/
|
||||
this.threshold = 1 / 0;
|
||||
this.warmupTime = 100;
|
||||
this.warmupIterations = 5;
|
||||
this.time = 500;
|
||||
this.iterations = 10;
|
||||
this.now = A;
|
||||
this.now = (e = t.now) != null ? e : this.now, this.warmupTime = (r = t.warmupTime) != null ? r : this.warmupTime, this.warmupIterations = (i = t.warmupIterations) != null ? i : this.warmupIterations, this.time = (c = t.time) != null ? c : this.time, this.iterations = (h = t.iterations) != null ? h : this.iterations, this.signal = t.signal, this.throws = (p = t.throws) != null ? p : !1, this.setup = (a = t.setup) != null ? a : () => {
|
||||
}, this.teardown = (l = t.teardown) != null ? l : () => {
|
||||
}, this.signal && this.signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
this.dispatchEvent(o("abort"));
|
||||
},
|
||||
{ once: !0 }
|
||||
);
|
||||
}
|
||||
runTask(t) {
|
||||
var e;
|
||||
return (e = this.signal) != null && e.aborted ? t : t.run();
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
async run() {
|
||||
if (this.concurrency === "bench")
|
||||
return this.runConcurrently(this.threshold, this.concurrency);
|
||||
this.dispatchEvent(o("start"));
|
||||
let t = [];
|
||||
for (let e of [...this._tasks.values()])
|
||||
t.push(await this.runTask(e));
|
||||
return this.dispatchEvent(o("complete")), t;
|
||||
}
|
||||
/**
|
||||
* See Bench.{@link concurrency}
|
||||
*/
|
||||
async runConcurrently(t = 1 / 0, e = "bench") {
|
||||
if (this.threshold = t, this.concurrency = e, e === "task")
|
||||
return this.run();
|
||||
this.dispatchEvent(o("start"));
|
||||
let r = y(t), i = [];
|
||||
for (let h of [...this._tasks.values()])
|
||||
i.push(r(() => this.runTask(h)));
|
||||
let c = await Promise.all(i);
|
||||
return this.dispatchEvent(o("complete")), c;
|
||||
}
|
||||
/**
|
||||
* warmup the benchmark tasks.
|
||||
* This is not run by default by the {@link run} method.
|
||||
*/
|
||||
async warmup() {
|
||||
if (this.concurrency === "bench") {
|
||||
await this.warmupConcurrently(this.threshold, this.concurrency);
|
||||
return;
|
||||
}
|
||||
this.dispatchEvent(o("warmup"));
|
||||
for (let [, t] of this._tasks)
|
||||
await t.warmup();
|
||||
}
|
||||
/**
|
||||
* warmup the benchmark tasks concurrently.
|
||||
* This is not run by default by the {@link runConcurrently} method.
|
||||
*/
|
||||
async warmupConcurrently(t = 1 / 0, e = "bench") {
|
||||
if (this.threshold = t, this.concurrency = e, e === "task") {
|
||||
await this.warmup();
|
||||
return;
|
||||
}
|
||||
this.dispatchEvent(o("warmup"));
|
||||
let r = y(t), i = [];
|
||||
for (let [, c] of this._tasks)
|
||||
i.push(r(() => c.warmup()));
|
||||
await Promise.all(i);
|
||||
}
|
||||
/**
|
||||
* reset each task and remove its result
|
||||
*/
|
||||
reset() {
|
||||
this.dispatchEvent(o("reset")), this._tasks.forEach((t) => {
|
||||
t.reset();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* add a benchmark task to the task map
|
||||
*/
|
||||
add(t, e, r = {}) {
|
||||
let i = new v(this, t, e, r);
|
||||
return this._tasks.set(t, i), this.dispatchEvent(o("add", i)), this;
|
||||
}
|
||||
/**
|
||||
* add a benchmark todo to the todo map
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
todo(t, e = () => {
|
||||
}, r = {}) {
|
||||
let i = new v(this, t, e, r);
|
||||
return this._todos.set(t, i), this.dispatchEvent(o("todo", i)), this;
|
||||
}
|
||||
/**
|
||||
* remove a benchmark task from the task map
|
||||
*/
|
||||
remove(t) {
|
||||
let e = this.getTask(t);
|
||||
return e && (this.dispatchEvent(o("remove", e)), this._tasks.delete(t)), this;
|
||||
}
|
||||
addEventListener(t, e, r) {
|
||||
super.addEventListener(t, e, r);
|
||||
}
|
||||
removeEventListener(t, e, r) {
|
||||
super.removeEventListener(t, e, r);
|
||||
}
|
||||
/**
|
||||
* table of the tasks results
|
||||
*/
|
||||
table(t) {
|
||||
return this.tasks.map((e) => {
|
||||
if (e.result) {
|
||||
if (e.result.error)
|
||||
throw e.result.error;
|
||||
return (t == null ? void 0 : t(e)) || {
|
||||
"Task Name": e.name,
|
||||
"ops/sec": e.result.error ? "NaN" : parseInt(e.result.hz.toString(), 10).toLocaleString(),
|
||||
"Average Time (ns)": e.result.error ? "NaN" : e.result.mean * 1e3 * 1e3,
|
||||
Margin: e.result.error ? "NaN" : `\xB1${e.result.rme.toFixed(2)}%`,
|
||||
Samples: e.result.error ? "NaN" : e.result.samples.length
|
||||
};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* (getter) tasks results as an array
|
||||
*/
|
||||
get results() {
|
||||
return [...this._tasks.values()].map((t) => t.result);
|
||||
}
|
||||
/**
|
||||
* (getter) tasks as an array
|
||||
*/
|
||||
get tasks() {
|
||||
return [...this._tasks.values()];
|
||||
}
|
||||
get todos() {
|
||||
return [...this._todos.values()];
|
||||
}
|
||||
/**
|
||||
* get a task based on the task name
|
||||
*/
|
||||
getTask(t) {
|
||||
return this._tasks.get(t);
|
||||
}
|
||||
};
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
Bench,
|
||||
Task,
|
||||
hrtimeNow,
|
||||
now
|
||||
});
|
||||
319
node_modules/tinybench/dist/index.d.cts
generated
vendored
Normal file
319
node_modules/tinybench/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
/**
|
||||
* 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);
|
||||
private loop;
|
||||
/**
|
||||
* 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?: AddEventListenerOptionsArgument): void;
|
||||
removeEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(type: K, listener: T, options?: RemoveEventListenerOptionsArgument): 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 = {
|
||||
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' | 'complete' | 'error' | 'reset' | 'start' | 'warmup' | 'cycle' | 'add' | 'remove' | 'todo';
|
||||
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;
|
||||
/**
|
||||
* Throw if a task fails (events will not work if true)
|
||||
*/
|
||||
throws?: boolean;
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
type RemoveEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.removeEventListener>[2];
|
||||
type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2];
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
/**
|
||||
* Executes tasks concurrently based on the specified concurrency mode.
|
||||
*
|
||||
* - When `mode` is set to `null` (default), concurrency is disabled.
|
||||
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
||||
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
||||
*/
|
||||
concurrency: 'task' | 'bench' | null;
|
||||
/**
|
||||
* The maximum number of concurrent tasks to run. Defaults to Infinity.
|
||||
*/
|
||||
threshold: number;
|
||||
signal?: AbortSignal;
|
||||
throws: boolean;
|
||||
warmupTime: number;
|
||||
warmupIterations: number;
|
||||
time: number;
|
||||
iterations: number;
|
||||
now: () => number;
|
||||
setup: Hook;
|
||||
teardown: Hook;
|
||||
constructor(options?: Options);
|
||||
private runTask;
|
||||
/**
|
||||
* 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[]>;
|
||||
/**
|
||||
* See Bench.{@link concurrency}
|
||||
*/
|
||||
runConcurrently(threshold?: number, mode?: NonNullable<Bench['concurrency']>): Promise<Task[]>;
|
||||
/**
|
||||
* warmup the benchmark tasks.
|
||||
* This is not run by default by the {@link run} method.
|
||||
*/
|
||||
warmup(): Promise<void>;
|
||||
/**
|
||||
* warmup the benchmark tasks concurrently.
|
||||
* This is not run by default by the {@link runConcurrently} method.
|
||||
*/
|
||||
warmupConcurrently(threshold?: number, mode?: NonNullable<Bench['concurrency']>): 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?: AddEventListenerOptionsArgument): void;
|
||||
removeEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(type: K, listener: T, options?: RemoveEventListenerOptionsArgument): void;
|
||||
/**
|
||||
* table of the tasks results
|
||||
*/
|
||||
table(convert?: (task: Task) => Record<string, string | number> | undefined): (Record<string, string | 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 hrtimeNow: () => number;
|
||||
declare const now: () => number;
|
||||
|
||||
export { Bench, type BenchEvent, type BenchEvents, type Fn, type Hook, type Options, Task, type TaskEvents, type TaskResult, hrtimeNow, now };
|
||||
319
node_modules/tinybench/dist/index.d.ts
generated
vendored
Normal file
319
node_modules/tinybench/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
/**
|
||||
* 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);
|
||||
private loop;
|
||||
/**
|
||||
* 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?: AddEventListenerOptionsArgument): void;
|
||||
removeEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(type: K, listener: T, options?: RemoveEventListenerOptionsArgument): 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 = {
|
||||
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' | 'complete' | 'error' | 'reset' | 'start' | 'warmup' | 'cycle' | 'add' | 'remove' | 'todo';
|
||||
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;
|
||||
/**
|
||||
* Throw if a task fails (events will not work if true)
|
||||
*/
|
||||
throws?: boolean;
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
type RemoveEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.removeEventListener>[2];
|
||||
type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2];
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
/**
|
||||
* Executes tasks concurrently based on the specified concurrency mode.
|
||||
*
|
||||
* - When `mode` is set to `null` (default), concurrency is disabled.
|
||||
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
||||
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
||||
*/
|
||||
concurrency: 'task' | 'bench' | null;
|
||||
/**
|
||||
* The maximum number of concurrent tasks to run. Defaults to Infinity.
|
||||
*/
|
||||
threshold: number;
|
||||
signal?: AbortSignal;
|
||||
throws: boolean;
|
||||
warmupTime: number;
|
||||
warmupIterations: number;
|
||||
time: number;
|
||||
iterations: number;
|
||||
now: () => number;
|
||||
setup: Hook;
|
||||
teardown: Hook;
|
||||
constructor(options?: Options);
|
||||
private runTask;
|
||||
/**
|
||||
* 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[]>;
|
||||
/**
|
||||
* See Bench.{@link concurrency}
|
||||
*/
|
||||
runConcurrently(threshold?: number, mode?: NonNullable<Bench['concurrency']>): Promise<Task[]>;
|
||||
/**
|
||||
* warmup the benchmark tasks.
|
||||
* This is not run by default by the {@link run} method.
|
||||
*/
|
||||
warmup(): Promise<void>;
|
||||
/**
|
||||
* warmup the benchmark tasks concurrently.
|
||||
* This is not run by default by the {@link runConcurrently} method.
|
||||
*/
|
||||
warmupConcurrently(threshold?: number, mode?: NonNullable<Bench['concurrency']>): 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?: AddEventListenerOptionsArgument): void;
|
||||
removeEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(type: K, listener: T, options?: RemoveEventListenerOptionsArgument): void;
|
||||
/**
|
||||
* table of the tasks results
|
||||
*/
|
||||
table(convert?: (task: Task) => Record<string, string | number> | undefined): (Record<string, string | 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 hrtimeNow: () => number;
|
||||
declare const now: () => number;
|
||||
|
||||
export { Bench, type BenchEvent, type BenchEvents, type Fn, type Hook, type Options, Task, type TaskEvents, type TaskResult, hrtimeNow, now };
|
||||
560
node_modules/tinybench/dist/index.js
generated
vendored
Normal file
560
node_modules/tinybench/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,560 @@
|
||||
var $ = Object.defineProperty;
|
||||
var C = (s) => {
|
||||
throw TypeError(s);
|
||||
};
|
||||
var D = (s, n, t) => n in s ? $(s, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[n] = t;
|
||||
var O = (s, n, t) => D(s, typeof n != "symbol" ? n + "" : n, t), q = (s, n, t) => n.has(s) || C("Cannot " + t);
|
||||
var d = (s, n, t) => (q(s, n, "read from private field"), t ? t.call(s) : n.get(s)), k = (s, n, t) => n.has(s) ? C("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(s) : n.set(s, t), f = (s, n, t, e) => (q(s, n, "write to private field"), e ? e.call(s, t) : n.set(s, t), t);
|
||||
var F = (s, n, t, e) => ({
|
||||
set _(r) {
|
||||
f(s, n, r, t);
|
||||
},
|
||||
get _() {
|
||||
return d(s, n, e);
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
||||
var M = class {
|
||||
constructor(n) {
|
||||
O(this, "value");
|
||||
O(this, "next");
|
||||
this.value = n;
|
||||
}
|
||||
}, m, w, E, g = class {
|
||||
constructor() {
|
||||
k(this, m);
|
||||
k(this, w);
|
||||
k(this, E);
|
||||
this.clear();
|
||||
}
|
||||
enqueue(n) {
|
||||
let t = new M(n);
|
||||
d(this, m) ? (d(this, w).next = t, f(this, w, t)) : (f(this, m, t), f(this, w, t)), F(this, E)._++;
|
||||
}
|
||||
dequeue() {
|
||||
let n = d(this, m);
|
||||
if (n)
|
||||
return f(this, m, d(this, m).next), F(this, E)._--, n.value;
|
||||
}
|
||||
clear() {
|
||||
f(this, m, void 0), f(this, w, void 0), f(this, E, 0);
|
||||
}
|
||||
get size() {
|
||||
return d(this, E);
|
||||
}
|
||||
*[Symbol.iterator]() {
|
||||
let n = d(this, m);
|
||||
for (; n; )
|
||||
yield n.value, n = n.next;
|
||||
}
|
||||
};
|
||||
m = new WeakMap(), w = new WeakMap(), E = new WeakMap();
|
||||
|
||||
// node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
||||
function y(s) {
|
||||
if (!((Number.isInteger(s) || s === Number.POSITIVE_INFINITY) && s > 0))
|
||||
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
||||
let n = new g(), t = 0, e = () => {
|
||||
t--, n.size > 0 && n.dequeue()();
|
||||
}, r = async (h, p, a) => {
|
||||
t++;
|
||||
let l = (async () => h(...a))();
|
||||
p(l);
|
||||
try {
|
||||
await l;
|
||||
} catch (T) {
|
||||
}
|
||||
e();
|
||||
}, i = (h, p, a) => {
|
||||
n.enqueue(r.bind(void 0, h, p, a)), (async () => (await Promise.resolve(), t < s && n.size > 0 && n.dequeue()()))();
|
||||
}, c = (h, ...p) => new Promise((a) => {
|
||||
i(h, a, p);
|
||||
});
|
||||
return Object.defineProperties(c, {
|
||||
activeCount: {
|
||||
get: () => t
|
||||
},
|
||||
pendingCount: {
|
||||
get: () => n.size
|
||||
},
|
||||
clearQueue: {
|
||||
value: () => {
|
||||
n.clear();
|
||||
}
|
||||
}
|
||||
}), c;
|
||||
}
|
||||
|
||||
// src/event.ts
|
||||
function o(s, n = null) {
|
||||
let t = new Event(s);
|
||||
return n && Object.defineProperty(t, "task", {
|
||||
value: n,
|
||||
enumerable: !0,
|
||||
writable: !1,
|
||||
configurable: !1
|
||||
}), t;
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var G = {
|
||||
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
|
||||
}, N = G;
|
||||
|
||||
// src/utils.ts
|
||||
var J = (s) => s / 1e6, U = () => J(Number(process.hrtime.bigint())), B = () => performance.now();
|
||||
function W(s) {
|
||||
return s !== null && typeof s == "object" && typeof s.then == "function";
|
||||
}
|
||||
var S = (s, n) => s.reduce((e, r) => e + (r - n) ** 2, 0) / (s.length - 1) || 0, X = (async () => {
|
||||
}).constructor, Z = (s) => s.constructor === X, z = async (s) => {
|
||||
if (Z(s.fn))
|
||||
return !0;
|
||||
try {
|
||||
if (s.opts.beforeEach != null)
|
||||
try {
|
||||
await s.opts.beforeEach.call(s);
|
||||
} catch (e) {
|
||||
}
|
||||
let n = s.fn(), t = W(n);
|
||||
if (t)
|
||||
try {
|
||||
await n;
|
||||
} catch (e) {
|
||||
}
|
||||
if (s.opts.afterEach != null)
|
||||
try {
|
||||
await s.opts.afterEach.call(s);
|
||||
} catch (e) {
|
||||
}
|
||||
return t;
|
||||
} catch (n) {
|
||||
return !1;
|
||||
}
|
||||
};
|
||||
|
||||
// src/task.ts
|
||||
var b = class extends EventTarget {
|
||||
constructor(t, e, r, i = {}) {
|
||||
super();
|
||||
/*
|
||||
* the number of times the task
|
||||
* function has been executed
|
||||
*/
|
||||
this.runs = 0;
|
||||
this.bench = t, this.name = e, this.fn = r, this.opts = i;
|
||||
}
|
||||
async loop(t, e) {
|
||||
var T;
|
||||
let r = this.bench.concurrency === "task", { threshold: i } = this.bench, c = 0, h = [];
|
||||
if (this.opts.beforeAll != null)
|
||||
try {
|
||||
await this.opts.beforeAll.call(this);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
let p = await z(this), a = async () => {
|
||||
this.opts.beforeEach != null && await this.opts.beforeEach.call(this);
|
||||
let u = 0;
|
||||
if (p) {
|
||||
let v = this.bench.now();
|
||||
await this.fn.call(this), u = this.bench.now() - v;
|
||||
} else {
|
||||
let v = this.bench.now();
|
||||
this.fn.call(this), u = this.bench.now() - v;
|
||||
}
|
||||
h.push(u), c += u, this.opts.afterEach != null && await this.opts.afterEach.call(this);
|
||||
}, l = y(i);
|
||||
try {
|
||||
let u = [];
|
||||
for (; (c < t || h.length + l.activeCount + l.pendingCount < e) && !((T = this.bench.signal) != null && T.aborted); )
|
||||
r ? u.push(l(a)) : await a();
|
||||
u.length && await Promise.all(u);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
if (this.opts.afterAll != null)
|
||||
try {
|
||||
await this.opts.afterAll.call(this);
|
||||
} catch (u) {
|
||||
return { error: u };
|
||||
}
|
||||
return { samples: h };
|
||||
}
|
||||
/**
|
||||
* run the current task and write the results in `Task.result` object
|
||||
*/
|
||||
async run() {
|
||||
var r, i;
|
||||
if ((r = this.result) != null && r.error)
|
||||
return this;
|
||||
this.dispatchEvent(o("start", this)), await this.bench.setup(this, "run");
|
||||
let { samples: t, error: e } = await this.loop(this.bench.time, this.bench.iterations);
|
||||
if (this.bench.teardown(this, "run"), t) {
|
||||
let c = t.reduce((L, A) => L + A, 0);
|
||||
this.runs = t.length, t.sort((L, A) => L - A);
|
||||
let h = c / this.runs, p = 1e3 / h, a = t.length, l = a - 1, T = t[0], u = t[l], v = c / t.length || 0, P = S(t, v), R = Math.sqrt(P), I = R / Math.sqrt(a), _ = N[String(Math.round(l) || 1)] || N.infinity, K = I * _, j = K / v * 100, H = t[Math.ceil(a * 0.75) - 1], V = t[Math.ceil(a * 0.99) - 1], Q = t[Math.ceil(a * 0.995) - 1], Y = t[Math.ceil(a * 0.999) - 1];
|
||||
if ((i = this.bench.signal) != null && i.aborted)
|
||||
return this;
|
||||
this.setResult({
|
||||
totalTime: c,
|
||||
min: T,
|
||||
max: u,
|
||||
hz: p,
|
||||
period: h,
|
||||
samples: t,
|
||||
mean: v,
|
||||
variance: P,
|
||||
sd: R,
|
||||
sem: I,
|
||||
df: l,
|
||||
critical: _,
|
||||
moe: K,
|
||||
rme: j,
|
||||
p75: H,
|
||||
p99: V,
|
||||
p995: Q,
|
||||
p999: Y
|
||||
});
|
||||
}
|
||||
if (e) {
|
||||
if (this.setResult({ error: e }), this.bench.throws)
|
||||
throw e;
|
||||
this.dispatchEvent(o("error", this)), this.bench.dispatchEvent(o("error", this));
|
||||
}
|
||||
return this.dispatchEvent(o("cycle", this)), this.bench.dispatchEvent(o("cycle", this)), this.dispatchEvent(o("complete", this)), this;
|
||||
}
|
||||
/**
|
||||
* warmup the current task
|
||||
*/
|
||||
async warmup() {
|
||||
var e;
|
||||
if ((e = this.result) != null && e.error)
|
||||
return;
|
||||
this.dispatchEvent(o("warmup", this)), await this.bench.setup(this, "warmup");
|
||||
let { error: t } = await this.loop(this.bench.warmupTime, this.bench.warmupIterations);
|
||||
if (this.bench.teardown(this, "warmup"), t && (this.setResult({ error: t }), this.bench.throws))
|
||||
throw t;
|
||||
}
|
||||
addEventListener(t, e, r) {
|
||||
super.addEventListener(t, e, r);
|
||||
}
|
||||
removeEventListener(t, e, r) {
|
||||
super.removeEventListener(t, e, r);
|
||||
}
|
||||
/**
|
||||
* change the result object values
|
||||
*/
|
||||
setResult(t) {
|
||||
this.result = { ...this.result, ...t }, Object.freeze(this.result);
|
||||
}
|
||||
/**
|
||||
* reset the task to make the `Task.runs` a zero-value and remove the `Task.result`
|
||||
* object
|
||||
*/
|
||||
reset() {
|
||||
this.dispatchEvent(o("reset", this)), this.runs = 0, this.result = void 0;
|
||||
}
|
||||
};
|
||||
|
||||
// src/bench.ts
|
||||
var x = class extends EventTarget {
|
||||
constructor(t = {}) {
|
||||
var e, r, i, c, h, p, a, l;
|
||||
super();
|
||||
/*
|
||||
* @private the task map
|
||||
*/
|
||||
this._tasks = /* @__PURE__ */ new Map();
|
||||
this._todos = /* @__PURE__ */ new Map();
|
||||
/**
|
||||
* Executes tasks concurrently based on the specified concurrency mode.
|
||||
*
|
||||
* - When `mode` is set to `null` (default), concurrency is disabled.
|
||||
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
||||
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
||||
*/
|
||||
this.concurrency = null;
|
||||
/**
|
||||
* The maximum number of concurrent tasks to run. Defaults to Infinity.
|
||||
*/
|
||||
this.threshold = 1 / 0;
|
||||
this.warmupTime = 100;
|
||||
this.warmupIterations = 5;
|
||||
this.time = 500;
|
||||
this.iterations = 10;
|
||||
this.now = B;
|
||||
this.now = (e = t.now) != null ? e : this.now, this.warmupTime = (r = t.warmupTime) != null ? r : this.warmupTime, this.warmupIterations = (i = t.warmupIterations) != null ? i : this.warmupIterations, this.time = (c = t.time) != null ? c : this.time, this.iterations = (h = t.iterations) != null ? h : this.iterations, this.signal = t.signal, this.throws = (p = t.throws) != null ? p : !1, this.setup = (a = t.setup) != null ? a : () => {
|
||||
}, this.teardown = (l = t.teardown) != null ? l : () => {
|
||||
}, this.signal && this.signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
this.dispatchEvent(o("abort"));
|
||||
},
|
||||
{ once: !0 }
|
||||
);
|
||||
}
|
||||
runTask(t) {
|
||||
var e;
|
||||
return (e = this.signal) != null && e.aborted ? t : t.run();
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
async run() {
|
||||
if (this.concurrency === "bench")
|
||||
return this.runConcurrently(this.threshold, this.concurrency);
|
||||
this.dispatchEvent(o("start"));
|
||||
let t = [];
|
||||
for (let e of [...this._tasks.values()])
|
||||
t.push(await this.runTask(e));
|
||||
return this.dispatchEvent(o("complete")), t;
|
||||
}
|
||||
/**
|
||||
* See Bench.{@link concurrency}
|
||||
*/
|
||||
async runConcurrently(t = 1 / 0, e = "bench") {
|
||||
if (this.threshold = t, this.concurrency = e, e === "task")
|
||||
return this.run();
|
||||
this.dispatchEvent(o("start"));
|
||||
let r = y(t), i = [];
|
||||
for (let h of [...this._tasks.values()])
|
||||
i.push(r(() => this.runTask(h)));
|
||||
let c = await Promise.all(i);
|
||||
return this.dispatchEvent(o("complete")), c;
|
||||
}
|
||||
/**
|
||||
* warmup the benchmark tasks.
|
||||
* This is not run by default by the {@link run} method.
|
||||
*/
|
||||
async warmup() {
|
||||
if (this.concurrency === "bench") {
|
||||
await this.warmupConcurrently(this.threshold, this.concurrency);
|
||||
return;
|
||||
}
|
||||
this.dispatchEvent(o("warmup"));
|
||||
for (let [, t] of this._tasks)
|
||||
await t.warmup();
|
||||
}
|
||||
/**
|
||||
* warmup the benchmark tasks concurrently.
|
||||
* This is not run by default by the {@link runConcurrently} method.
|
||||
*/
|
||||
async warmupConcurrently(t = 1 / 0, e = "bench") {
|
||||
if (this.threshold = t, this.concurrency = e, e === "task") {
|
||||
await this.warmup();
|
||||
return;
|
||||
}
|
||||
this.dispatchEvent(o("warmup"));
|
||||
let r = y(t), i = [];
|
||||
for (let [, c] of this._tasks)
|
||||
i.push(r(() => c.warmup()));
|
||||
await Promise.all(i);
|
||||
}
|
||||
/**
|
||||
* reset each task and remove its result
|
||||
*/
|
||||
reset() {
|
||||
this.dispatchEvent(o("reset")), this._tasks.forEach((t) => {
|
||||
t.reset();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* add a benchmark task to the task map
|
||||
*/
|
||||
add(t, e, r = {}) {
|
||||
let i = new b(this, t, e, r);
|
||||
return this._tasks.set(t, i), this.dispatchEvent(o("add", i)), this;
|
||||
}
|
||||
/**
|
||||
* add a benchmark todo to the todo map
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
todo(t, e = () => {
|
||||
}, r = {}) {
|
||||
let i = new b(this, t, e, r);
|
||||
return this._todos.set(t, i), this.dispatchEvent(o("todo", i)), this;
|
||||
}
|
||||
/**
|
||||
* remove a benchmark task from the task map
|
||||
*/
|
||||
remove(t) {
|
||||
let e = this.getTask(t);
|
||||
return e && (this.dispatchEvent(o("remove", e)), this._tasks.delete(t)), this;
|
||||
}
|
||||
addEventListener(t, e, r) {
|
||||
super.addEventListener(t, e, r);
|
||||
}
|
||||
removeEventListener(t, e, r) {
|
||||
super.removeEventListener(t, e, r);
|
||||
}
|
||||
/**
|
||||
* table of the tasks results
|
||||
*/
|
||||
table(t) {
|
||||
return this.tasks.map((e) => {
|
||||
if (e.result) {
|
||||
if (e.result.error)
|
||||
throw e.result.error;
|
||||
return (t == null ? void 0 : t(e)) || {
|
||||
"Task Name": e.name,
|
||||
"ops/sec": e.result.error ? "NaN" : parseInt(e.result.hz.toString(), 10).toLocaleString(),
|
||||
"Average Time (ns)": e.result.error ? "NaN" : e.result.mean * 1e3 * 1e3,
|
||||
Margin: e.result.error ? "NaN" : `\xB1${e.result.rme.toFixed(2)}%`,
|
||||
Samples: e.result.error ? "NaN" : e.result.samples.length
|
||||
};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* (getter) tasks results as an array
|
||||
*/
|
||||
get results() {
|
||||
return [...this._tasks.values()].map((t) => t.result);
|
||||
}
|
||||
/**
|
||||
* (getter) tasks as an array
|
||||
*/
|
||||
get tasks() {
|
||||
return [...this._tasks.values()];
|
||||
}
|
||||
get todos() {
|
||||
return [...this._todos.values()];
|
||||
}
|
||||
/**
|
||||
* get a task based on the task name
|
||||
*/
|
||||
getTask(t) {
|
||||
return this._tasks.get(t);
|
||||
}
|
||||
};
|
||||
export {
|
||||
x as Bench,
|
||||
b as Task,
|
||||
U as hrtimeNow,
|
||||
B as now
|
||||
};
|
||||
27
node_modules/tinybench/package.json
generated
vendored
Normal file
27
node_modules/tinybench/package.json
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "tinybench",
|
||||
"version": "2.9.0",
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@8.4.0",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.cts",
|
||||
"exports": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"repository": "tinylibs/tinybench",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"benchmark",
|
||||
"tinylibs",
|
||||
"tiny"
|
||||
],
|
||||
"scripts": {
|
||||
"publish": "npm run build && clean-publish"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user