@@ -6,8 +6,7 @@ _I'm transitioning to a full-time open source career. Your support would be grea
66[ ![ CI] ( https://github.com/tinylibs/tinybench/actions/workflows/test.yml/badge.svg?branch=main )] ( https://github.com/tinylibs/tinybench/actions/workflows/test.yml )
77[ ![ NPM version] ( https://img.shields.io/npm/v/tinybench.svg?style=flat )] ( https://www.npmjs.com/package/tinybench )
88
9- Benchmark your code easily with Tinybench, a simple, tiny and light-weight ` 7KB ` (` 2KB ` minified and gzipped)
10- benchmarking library!
9+ Benchmark your code easily with Tinybench, a simple, tiny and light-weight ` 10KB ` (` 2KB ` minified and gzipped) benchmarking library!
1110You can run your benchmarks in multiple JavaScript runtimes, Tinybench is
1211completely based on the Web APIs with proper timing using ` process.hrtime ` or
1312` performance.now ` .
@@ -23,7 +22,7 @@ _In case you need more tiny libraries like tinypool or tinyspy, please consider
2322
2423## Installing
2524
26- ``` bash
25+ ``` shell
2726$ npm install -D tinybench
2827```
2928
@@ -52,12 +51,12 @@ await bench.run();
5251console .table (bench .table ());
5352
5453// Output:
55- // ┌─────────┬───────────────┬──────────┬ ──────────────────────┬ ──────────┬──────────────────────────────────┬─────────┐
56- // │ (index) │ Task name │ ops/sec │ Average time/op (ns ) │ Margin │ Median time/op (ns) │ Samples │
57- // ├─────────┼───────────────┼──────────┼ ──────────────────────┼ ──────────┼──────────────────────────────────┼─────────┤
58- // │ 0 │ 'faster task' │ '38,832' │ 25751.297631307978 │ '±3.48 %' │ '22016.49999997812±5.5000000145' │ 3884 │
59- // │ 1 │ 'slower task' │ '669 ' │ 1493338.567164177 │ '±5.98 %' │ '1445076.0000000286 ' │ 67 │
60- // └─────────┴───────────────┴──────────┴ ──────────────────────┴ ──────────┴──────────────────────────────────┴─────────┘
54+ // ┌─────────┬───────────────┬────────────────────────────┬ ─────────────────────────── ┬──────────────────────┬ ─────────────────────┬─────────┐
55+ // │ (index) │ Task name │ Throughput average ( ops/s) │ Throughput median (ops/s ) │ Latency average (ns) │ Latency median (ns) │ Samples │
56+ // ├─────────┼───────────────┼────────────────────────────┼ ─────────────────────────── ┼──────────────────────┼ ─────────────────────┼─────────┤
57+ // │ 0 │ 'faster task' │ '102906 ± 0.89%' │ '82217 ± 14' │ '11909.14 ± 3.95 %' │ '12163.00 ± 2.00' │ 8398 │
58+ // │ 1 │ 'slower task' │ '988 ± 26.26% ' │ '710' │ '1379560.47 ± 6.72 %' │ '1408552.00 ' │ 73 │
59+ // └─────────┴───────────────┴────────────────────────────┴ ─────────────────────────── ┴──────────────────────┴ ─────────────────────┴─────────┘
6160```
6261
6362The ` add ` method accepts a task name and a task function, so it can benchmark
@@ -164,6 +163,8 @@ function has been executed.
164163- ` setResult(result: Partial<TaskResult>) ` : change the result object values
165164- ` reset() ` : reset the task to make the ` Task.runs ` a zero-value and remove the ` Task.result ` object
166165
166+ FnOptions:
167+
167168``` ts
168169export interface FnOptions {
169170 /**
@@ -188,118 +189,136 @@ export interface FnOptions {
188189}
189190```
190191
191- ## ` TaskResult `
192+ ### ` TaskResult `
192193
193- the benchmark task result object.
194+ The benchmark task result object:
194195
195196``` ts
196197export interface TaskResult {
197198 /*
198- * the last error that was thrown while running the task
199+ * the last task error that was thrown
199200 */
200- error? : unknown ;
201+ error? : Error ;
201202
202203 /**
203- * The amount of time in milliseconds to run the benchmark task (cycle).
204+ * the time to run the task benchmark cycle (ms)
204205 */
205206 totalTime: number ;
206207
207208 /**
208- * the minimum value in the samples
209+ * how long each operation takes (ms)
209210 */
210- min: number ;
211+ period: number ;
212+
211213 /**
212- * the maximum value in the samples
214+ * the task latency statistics
213215 */
214- max: number ;
216+ latency: Statistics ;
217+
218+ /**
219+ * the task throughput statistics
220+ */
221+ throughput: Statistics ;
215222
216223 /**
217224 * the number of operations per second
225+ * @deprecated use `.throughput.mean` instead
218226 */
219227 hz: number ;
220228
221229 /**
222- * how long each operation takes (ms)
230+ * latency samples (ms)
231+ * @deprecated use `.latency.samples` instead
223232 */
224- period : number ;
233+ samples : number [] ;
225234
226235 /**
227- * task samples of each task iteration time (ms)
236+ * the minimum latency samples value
237+ * @deprecated use `.latency.min` instead
228238 */
229- samples: number [];
239+ min: number ;
240+ /**
241+ * the maximum latency samples value
242+ * @deprecated use `.latency.max` instead
243+ */
244+ max: number ;
230245
231246 /**
232- * samples mean/average (estimate of the population mean)
247+ * the latency samples mean/average (estimate of the population mean/average)
248+ * @deprecated use `.latency.mean` instead
233249 */
234250 mean: number ;
235251
236252 /**
237- * samples variance (estimate of the population variance)
253+ * the latency samples variance (estimate of the population variance)
254+ * @deprecated use `.latency.variance` instead
238255 */
239256 variance: number ;
240257
241258 /**
242- * samples standard deviation (estimate of the population standard deviation)
259+ * the latency samples standard deviation (estimate of the population standard deviation)
260+ * @deprecated use `.latency.sd` instead
243261 */
244262 sd: number ;
245263
246264 /**
247- * standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
265+ * the latency standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean/average)
266+ * @deprecated use `.latency.sem` instead
248267 */
249268 sem: number ;
250269
251270 /**
252- * degrees of freedom
271+ * the latency samples degrees of freedom
272+ * @deprecated use `.latency.df` instead
253273 */
254274 df: number ;
255275
256276 /**
257- * critical value of the samples
277+ * the latency samples critical value
278+ * @deprecated use `.latency.critical` instead
258279 */
259280 critical: number ;
260281
261282 /**
262- * margin of error
283+ * the latency samples margin of error
284+ * @deprecated use `.latency.moe` instead
263285 */
264286 moe: number ;
265287
266288 /**
267- * relative margin of error
289+ * the latency samples relative margin of error
290+ * @deprecated use `.latency.rme` instead
268291 */
269292 rme: number ;
270293
271294 /**
272- * median absolute deviation
273- */
274- mad: number ;
275-
276- /**
277- * p50/median percentile
278- */
279- p50: number ;
280-
281- /**
282- * p75 percentile
295+ * the latency samples p75 percentile
296+ * @deprecated use `.latency.p75` instead
283297 */
284298 p75: number ;
285299
286300 /**
287- * p99 percentile
301+ * the latency samples p99 percentile
302+ * @deprecated use `.latency.p99` instead
288303 */
289304 p99: number ;
290305
291306 /**
292- * p995 percentile
307+ * the latency samples p995 percentile
308+ * @deprecated use `.latency.p995` instead
293309 */
294310 p995: number ;
295311
296312 /**
297- * p999 percentile
313+ * the latency samples p999 percentile
314+ * @deprecated use `.latency.p999` instead
298315 */
299316 p999: number ;
300317}
301318```
302319
320+ [ Statistics] ( https://github.com/tinylibs/tinybench/blob/main/src/types.ts#L30 ) type definition.
321+
303322### ` Events `
304323
305324Both the ` Task ` and ` Bench ` objects extend the ` EventTarget ` object, so you can attach listeners to different types of events
0 commit comments