File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed
Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ benchmark tasks to it.
3333``` js
3434import { Bench } from ' tinybench' ;
3535
36- const bench = new Bench ({ time: 100 });
36+ const bench = new Bench ({ name : ' simple benchmark ' , time: 100 });
3737
3838bench
3939 .add (' faster task' , () => {
4747await bench .warmup (); // make results more reliable
4848await bench .run ();
4949
50+ console .log (bench .name );
5051console .table (bench .table ());
5152
5253// Output:
54+ // simple benchmark
5355// ┌─────────┬───────────────┬────────────────────────────┬───────────────────────────┬──────────────────────┬─────────────────────┬─────────┐
5456// │ (index) │ Task name │ Throughput average (ops/s) │ Throughput median (ops/s) │ Latency average (ns) │ Latency median (ns) │ Samples │
5557// ├─────────┼───────────────┼────────────────────────────┼───────────────────────────┼──────────────────────┼─────────────────────┼─────────┤
@@ -79,6 +81,11 @@ Options:
7981
8082``` ts
8183export interface Options {
84+ /**
85+ * benchmark name
86+ */
87+ name? : string ;
88+
8289 /**
8390 * time needed for running a benchmark task (milliseconds) @default 500
8491 */
Original file line number Diff line number Diff line change 11/* eslint-disable no-console */
22import { Bench } from '../../src' ;
33
4- const bench = new Bench ( { time : 100 } ) ;
4+ const bench = new Bench ( { name : 'simple benchmark' , time : 100 } ) ;
55
66bench
77 . add ( 'faster task' , ( ) => {
1414
1515await bench . run ( ) ;
1616
17+ console . log ( bench . name ) ;
1718console . table ( bench . table ( ) ) ;
1819
1920// Output:
21+ // simple benchmark
2022// ┌─────────┬───────────────┬────────────────────────────┬───────────────────────────┬──────────────────────┬─────────────────────┬─────────┐
2123// │ (index) │ Task name │ Throughput average (ops/s) │ Throughput median (ops/s) │ Latency average (ns) │ Latency median (ns) │ Samples │
2224// ├─────────┼───────────────┼────────────────────────────┼───────────────────────────┼──────────────────────┼─────────────────────┼─────────┤
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ export default class Bench extends EventTarget {
3131 */
3232 private readonly _tasks = new Map < string , Task > ( ) ;
3333
34+ name ?: string ;
35+
3436 /**
3537 * Executes tasks concurrently based on the specified concurrency mode.
3638 *
@@ -65,6 +67,7 @@ export default class Bench extends EventTarget {
6567
6668 constructor ( options : Options = { } ) {
6769 super ( ) ;
70+ this . name = options . name ;
6871 this . now = options . now ?? this . now ;
6972 this . warmupTime = options . warmupTime ?? this . warmupTime ;
7073 this . warmupIterations = options . warmupIterations ?? this . warmupIterations ;
Original file line number Diff line number Diff line change @@ -307,6 +307,11 @@ export interface TaskEventsMap {
307307}
308308
309309export interface Options {
310+ /**
311+ * benchmark name
312+ */
313+ name ?: string ;
314+
310315 /**
311316 * time needed for running a benchmark task (milliseconds) @default 500
312317 */
You can’t perform that action at this time.
0 commit comments