1313 <a href =" #plugins " >Plugins</a >  ;  ;  ; |  ;  ;  ;
1414 <a href =" #using-reporter " >Using Reporter</a >  ;  ;  ; |  ;  ;  ;
1515 <a href =" #setup-and-teardown " >Setup and Teardown</a >  ;  ;  ; |  ;  ;  ;
16+ <a href =" #benchmark-modes " >Benchmark Modes</a >  ;  ;  ; |  ;  ;  ;
1617 <a href =" #writing-javascript-mistakes " >Writing JavaScript Mistakes</a >
1718</p >
1819
@@ -78,7 +79,9 @@ See the [examples folder](./examples/) for more common usage examples.
7879 3 . [ Custom Reporter] ( #custom-reporter )
79804 . [ Setup and Teardown] ( #setup-and-teardown )
8081 1 . [ Managed Benchmarks] ( #managed-benchmarks )
81-
82+ 5 . [ Benchmark Modes] ( #benchmark-modes )
83+ 1 . [ Operations Mode (Default)] ( #operations-mode )
84+ 2 . [ Time Mode] ( #time-mode )
8285## Class: ` Suite `
8386
8487> Stability: 1.1 Active Development
@@ -94,6 +97,11 @@ A `Suite` manages and executes benchmark functions. It provides two methods: `ad
9497 * ` opsSec ` {string} Operations per second.
9598 * ` iterations ` {Number} Number of iterations.
9699 * ` histogram ` {Histogram} Histogram instance.
100+ * ` benchmarkMode ` {string} Benchmark mode to use. Can be 'ops' or 'time'. ** Default:** ` 'ops' ` .
101+ * ` 'ops' ` - Measures operations per second (traditional benchmarking).
102+ * ` 'time' ` - Measures actual execution time for a single run.
103+ * ` useWorkers ` {boolean} Whether to run benchmarks in worker threads. ** Default:** ` false ` .
104+ * ` plugins ` {Array} Array of plugin instances to use.
97105
98106If no ` reporter ` is provided, results are printed to the console.
99107
@@ -130,7 +138,8 @@ Using delete property x 5,853,505 ops/sec (10 runs sampled) min..max=(169ns ...
130138### ` suite.run() `
131139
132140* Returns: ` {Promise<Array<Object>>} ` An array of benchmark results, each containing:
133- * ` opsSec ` {number} Operations per second.
141+ * ` opsSec ` {number} Operations per second (Only in 'ops' mode).
142+ * ` totalTime ` {number} Total execution time in seconds (Only in 'time' mode).
134143 * ` iterations ` {number} Number of executions of ` fn ` .
135144 * ` histogram ` {Histogram} Histogram of benchmark iterations.
136145 * ` name ` {string} Benchmark name.
@@ -481,6 +490,79 @@ const suite = new Suite({
481490});
482491```
483492
493+ ## Benchmark Modes
494+
495+ ` bench-node ` supports multiple benchmarking modes to measure code performance in different ways.
496+
497+ ### Operations Mode
498+
499+ Operations mode (default) measures how many operations can be performed in a given timeframe.
500+ This is the traditional benchmarking approach that reports results in operations per second (ops/sec).
501+
502+ This mode is best for:
503+ - Comparing relative performance between different implementations
504+ - Measuring throughput of small, fast operations
505+ - Traditional microbenchmarking
506+
507+ Example output:
508+ ```
509+ String concatenation x 12,345,678 ops/sec (11 runs sampled) v8-never-optimize=true min..max=(81ns...85ns)
510+ ```
511+
512+ ### Time Mode
513+
514+ Time mode measures the actual time taken to execute a function exactly once.
515+ This mode is useful when you want to measure the real execution time for operations that have a known, fixed duration.
516+
517+ This mode is best for:
518+ - Costly operations where multiple instructions are executed in a single run
519+ - Benchmarking operations with predictable timing
520+ - Verifying performance guarantees for time-sensitive functions
521+
522+ To use time mode, set the ` benchmarkMode ` option to ` 'time' ` when creating a Suite:
523+
524+ ``` js
525+ const { Suite } = require (' bench-node' );
526+
527+ const timeSuite = new Suite ({
528+ benchmarkMode: ' time' // Enable time mode
529+ });
530+
531+ // Create a function that takes a predictable amount of time
532+ const delay = (ms ) => new Promise (resolve => setTimeout (resolve, ms));
533+
534+ timeSuite .add (' Async Delay 100ms' , async () => {
535+ await delay (100 );
536+ });
537+
538+ timeSuite .add (' Sync Busy Wait 50ms' , () => {
539+ const start = Date .now ();
540+ while (Date .now () - start < 50 );
541+ });
542+
543+ // Optional: Run the benchmark multiple times with repeatSuite
544+ timeSuite .add (' Quick Operation with 5 repeats' , { repeatSuite: 5 }, () => {
545+ // This will run exactly once per repeat (5 times total)
546+ // and report the average time
547+ let x = 1 + 1 ;
548+ });
549+
550+ (async () => {
551+ await timeSuite .run ();
552+ })();
553+ ```
554+
555+ In time mode, results include ` totalTime ` (in seconds) instead of ` opsSec ` .
556+
557+ Example output:
558+ ```
559+ Async Delay 100ms x 0.1003s (1 sample) v8-never-optimize=true
560+ Sync Busy Wait 50ms x 0.0502s (1 sample) v8-never-optimize=true
561+ Quick Operation with 5 repeats x 0.0000s (5 samples) v8-never-optimize=true
562+ ```
563+
564+ See [ examples/time-mode.js] ( ./examples/time-mode.js ) for a complete example.
565+
484566## Writing JavaScript Mistakes
485567
486568When working on JavaScript micro-benchmarks, it’s easy to forget that modern engines use
0 commit comments