{
  "type": "module",
  "source": "doc/api/bench.md",
  "modules": [
    {
      "textRaw": "Benchmark runner",
      "name": "benchmark_runner",
      "introduced_in": "REPLACEME",
      "type": "module",
      "meta": {
        "added": [
          "REPLACEME"
        ],
        "changes": []
      },
      "stability": 1,
      "stabilityText": "Early Development",
      "desc": "<p>The <code>node:bench</code> module supports defining and running JavaScript benchmarks in\nthe current process. To access it:</p>\n<pre><code class=\"language-mjs\">import { bench, suite } from 'node:bench';\n</code></pre>\n<pre><code class=\"language-cjs\">const { bench, suite } = require('node:bench');\n</code></pre>\n<p>This module is only available under the <code>node:</code> scheme.</p>",
      "modules": [
        {
          "textRaw": "Example benchmark",
          "name": "example_benchmark",
          "type": "module",
          "desc": "<p>Save the following as <code>benchmark.mjs</code>:</p>\n<pre><code class=\"language-mjs\">import { bench, suite } from 'node:bench';\n\nsuite('URL', () => {\n  const input = 'https://example.com/a?b=c';\n\n  bench('construct', {\n    samples: 30,\n    params: { input: 'short' },\n  }, (b) => {\n    const operations = 10_000;\n\n    b.start();\n    for (let i = 0; i &#x3C; operations; i++) {\n      new URL(input);\n    }\n    b.end(operations);\n  });\n});\n</code></pre>\n<p>Run the benchmark from the command line:</p>\n<pre><code class=\"language-console\">node --bench benchmark.mjs\n</code></pre>\n<p>Benchmarks are executed serially in declaration order. Declared benchmarks are\nscheduled automatically. Call <code>run()</code> during the same turn as the declarations\nto consume the event stream or configure filtering.\nIf an automatically scheduled run fails and <code>run()</code> was not called, the process\nexit code is set to <code>1</code>.</p>",
          "displayName": "Example benchmark"
        },
        {
          "textRaw": "Measurement model",
          "name": "measurement_model",
          "type": "module",
          "desc": "<p>Each warmup and measured sample invokes the benchmark function once with a\nfresh {BenchContext}. The function must either call <code>context.start()</code> and\n<code>context.end(operations)</code> exactly once, or call <code>context.record(sample)</code> exactly\nonce to provide an externally measured sample. Setup before <code>start()</code> and\ncleanup after <code>end()</code> are outside the measured region. Promise-returning\nfunctions are awaited.</p>\n<p>By default, an event loop turn occurs between sample invocations. An embedded\nrunner can disable this using <code>yieldBetweenSamples</code>. The runner executes\nbenchmarks serially, but it does not provide process isolation. Other work in\nthe process, JIT compilation, garbage collection, CPU frequency changes, and\nsystem load can all affect results. Keep raw samples when comparing results and\ninvestigate noisy or skewed distributions rather than treating a confidence\ninterval as a pass/fail threshold.</p>\n<p>Calling <code>context.done()</code> during a measured sample completes the benchmark after\nthat sample. This allows a higher-level tool to treat <code>samples</code> as a maximum and\nimplement a dynamic sampling policy.</p>",
          "displayName": "Measurement model"
        },
        {
          "textRaw": "Reusable runners",
          "name": "reusable_runners",
          "type": "module",
          "desc": "<p>The module-level declaration functions use a shared runner and schedule it\nautomatically. Higher-level tools can create isolated, explicitly started\nrunners instead:</p>\n<pre><code class=\"language-mjs\">import { createRunner } from 'node:bench';\n\nconst runner = createRunner({ yieldBetweenSamples: false });\n\nrunner.bench('example', { samples: 100 }, (b) => {\n  const operations = chooseOperationCount();\n  b.start();\n  runOperations(operations);\n  const sample = b.end(operations);\n\n  if (hasEnoughData(sample)) b.done();\n});\n\nfor await (const record of runner.run()) {\n  // Consume structured benchmark records.\n}\n</code></pre>\n<p>Each runner has independent declarations, hooks, filtering, and output. Unlike\nthe module-level declarations, creating a benchmark on an explicit runner does\nnot schedule execution. This allows packages to collect declarations and start\nthem later. Calling the explicit runner's <code>run()</code> function prevents additional\ndeclarations and a second call to <code>run()</code> is an error.</p>",
          "displayName": "Reusable runners"
        },
        {
          "textRaw": "Command-line runner",
          "name": "command-line_runner",
          "type": "module",
          "desc": "<p>The <code>--bench</code> flag runs one or more explicit benchmark files or glob patterns:</p>\n<pre><code class=\"language-console\">node --bench benchmark.mjs\nnode --bench --bench-reporter=json 'benchmarks/**/*.js'\n</code></pre>\n<p>Files are sorted and executed serially. The default\n<code>--bench-isolation=process</code> mode runs each file in a separate child process and\nemits one aggregate summary. Structured events are transferred to the parent\nwithout JSON conversion, preserving BigInt durations, errors, and parameter\nvalues. Child writes to stdout and stderr are emitted as diagnostic records so\nthey do not corrupt reporter output.</p>\n<p><code>--bench-isolation=none</code> imports all files into the runner process. This mode\nhas lower startup overhead, but module, heap, and process state carry between\nfiles, and user writes share stdout and stderr with reporters.</p>\n<p>Benchmark files passed to <code>--bench</code> should declare benchmarks but must not call\n<code>run()</code>. The CLI supports <code>--bench-name-pattern</code>, <code>--bench-samples</code>,\n<code>--bench-warmup</code>, <code>--bench-reporter</code>, and <code>--bench-reporter-destination</code>. See\nthe <a href=\"cli.html#--bench\">command-line options documentation</a> for details.</p>",
          "displayName": "Command-line runner"
        },
        {
          "textRaw": "Benchmark reporters",
          "name": "benchmark_reporters",
          "type": "module",
          "desc": "<p>The built-in reporters are available from the scheme-only\n<code>node:bench/reporters</code> module:</p>\n<pre><code class=\"language-mjs\">import { json, spec } from 'node:bench/reporters';\n</code></pre>\n<pre><code class=\"language-cjs\">const { json, spec } = require('node:bench/reporters');\n</code></pre>\n<p>Reporter values can be passed directly to <code>stream.compose()</code>:</p>\n<pre><code class=\"language-mjs\">import { bench, run } from 'node:bench';\nimport { spec } from 'node:bench/reporters';\nimport process from 'node:process';\n\nbench('example', (b) => {\n  b.start();\n  doWork();\n  b.end(1);\n});\n\nrun().compose(spec).pipe(process.stdout);\n</code></pre>\n<p>The <code>spec</code> reporter buffers results and outputs a concise table containing the\nsample count, mean rate, 95% confidence interval for the mean, median rate, and\nwarnings. A coefficient of variation above 5% is reported as <code>noisy</code>, and an\nabsolute skewness above 1 is reported as <code>skewed</code>. The exact human-readable\nformat is subject to change.</p>\n<p>The <code>json</code> reporter emits every lifecycle record as newline-delimited JSON.\nBigInt values, including <code>duration_ns</code>, are encoded as decimal strings. Errors\nare represented using their <code>name</code>, <code>message</code>, <code>stack</code>, <code>code</code>, <code>cause</code>, and\n<code>errors</code> properties. As required by JSON, non-finite numbers are encoded as\n<code>null</code>.</p>\n<p>Custom reporters use the same composition contract. They can be transforms or\nfunctions accepted by <code>stream.compose()</code>. The composed readable can be piped to\nany writable destination:</p>\n<pre><code class=\"language-mjs\">import { run } from 'node:bench';\nimport process from 'node:process';\n\nasync function* names(source) {\n  for await (const { type, data } of source) {\n    if (type === 'bench:complete') {\n      yield `${data.name}\\n`;\n    }\n  }\n}\n\nrun().compose(names).pipe(process.stdout);\n</code></pre>",
          "displayName": "Benchmark reporters"
        },
        {
          "textRaw": "Sample result",
          "name": "sample_result",
          "type": "module",
          "desc": "<p>Each measured sample has the following properties:</p>\n<ul>\n<li><code>operations</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The positive operation count passed to <code>context.end()</code> or <code>context.record()</code>.</li>\n<li><code>duration_ns</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#bigint_type\"><code>&#x3C;bigint></code></a> The measured duration in nanoseconds.</li>\n<li><code>rate</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> Operations per second.</li>\n<li><code>detail</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#Data_types\"><code>&#x3C;any></code></a> The optional cloned sample detail.</li>\n</ul>",
          "displayName": "Sample result"
        },
        {
          "textRaw": "Benchmark result",
          "name": "benchmark_result",
          "type": "module",
          "desc": "<p>A completed benchmark result contains:</p>\n<ul>\n<li><code>benchId</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The stable benchmark identity.</li>\n<li><code>parentId</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#null_type\"><code>&#x3C;null></code></a> The stable containing suite identity.</li>\n<li><code>name</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The benchmark name.</li>\n<li><code>file</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The source file.</li>\n<li><code>line</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The source line.</li>\n<li><code>column</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The source column.</li>\n<li><code>tags</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>[] The inherited canonical tags.</li>\n<li><code>params</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> The canonical parameter metadata.</li>\n<li><code>samples</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a>[] The exact measured samples.</li>\n<li><code>summary</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a>\n<ul>\n<li><code>mean</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The arithmetic mean of per-sample rates.</li>\n<li><code>median</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The median per-sample rate.</li>\n<li><code>min</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The minimum per-sample rate.</li>\n<li><code>max</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The maximum per-sample rate.</li>\n<li><code>stddev</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The population standard deviation of rates.</li>\n<li><code>coefficientOfVariation</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> <code>stddev / mean</code>.</li>\n<li><code>confidenceInterval</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> The 95% Student's t confidence interval for\nthe mean rate, with <code>lower</code> and <code>upper</code> properties.</li>\n<li><code>medianConfidenceInterval</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> The 95% nonparametric confidence\ninterval for the median rate, with <code>lower</code> and <code>upper</code> properties.</li>\n<li><code>skewness</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The skewness of the scaled rate histogram.</li>\n</ul>\n</li>\n</ul>",
          "displayName": "Benchmark result"
        }
      ],
      "methods": [
        {
          "textRaw": "`createRunner([options])`",
          "name": "createRunner",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`options` {Object}",
                  "name": "options",
                  "type": "Object",
                  "options": [
                    {
                      "textRaw": "`yieldBetweenSamples` {boolean} Schedule an event loop turn between sample callbacks. Disabling this also prevents timer-based abort signals from firing between synchronous callbacks. Benchmark timeouts continue to be checked against a monotonic deadline. **Default:** `true`.",
                      "name": "yieldBetweenSamples",
                      "type": "boolean",
                      "default": "`true`",
                      "desc": "Schedule an event loop turn between sample callbacks. Disabling this also prevents timer-based abort signals from firing between synchronous callbacks. Benchmark timeouts continue to be checked against a monotonic deadline."
                    }
                  ],
                  "optional": true
                }
              ],
              "return": {
                "textRaw": "Returns: {Object} An isolated benchmark runner with bound `after`, `afterEach`, `before`, `beforeEach`, `bench`, `describe`, `run`, and `suite` functions.",
                "name": "return",
                "type": "Object",
                "desc": "An isolated benchmark runner with bound `after`, `afterEach`, `before`, `beforeEach`, `bench`, `describe`, `run`, and `suite` functions."
              }
            }
          ],
          "desc": "<p>Creates an explicitly started benchmark runner. Declarations made through one\nrunner do not interact with declarations made through another runner or through\nthe module-level functions. Call the returned <code>run()</code> function to start the\nrunner and obtain its {BenchmarksStream}.</p>\n<p>Each runner can be started once. Its <code>run()</code> function accepts the same options\nas the module-level <a href=\"#runoptions\"><code>run()</code></a>. <code>run({ yieldBetweenSamples })</code> overrides the\nvalue passed to <code>createRunner()</code>.</p>"
        },
        {
          "textRaw": "`bench([name][, options], fn)`",
          "name": "bench",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`name` {string} The benchmark name. **Default:** The `name` property of `fn`, or `'<anonymous>'` when `fn` has no name.",
                  "name": "name",
                  "type": "string",
                  "default": "The `name` property of `fn`, or `'<anonymous>'` when `fn` has no name",
                  "desc": "The benchmark name.",
                  "optional": true
                },
                {
                  "textRaw": "`options` {Object}",
                  "name": "options",
                  "type": "Object",
                  "options": [
                    {
                      "textRaw": "`only` {boolean} When any benchmark or containing suite has `only` set, benchmarks without `only` in their hierarchy are skipped. **Default:** `false`.",
                      "name": "only",
                      "type": "boolean",
                      "default": "`false`",
                      "desc": "When any benchmark or containing suite has `only` set, benchmarks without `only` in their hierarchy are skipped."
                    },
                    {
                      "textRaw": "`params` {Object} String, finite number, or boolean metadata identifying this benchmark configuration. Parameter keys are sorted when constructing the stable benchmark identity. **Default:** An empty object.",
                      "name": "params",
                      "type": "Object",
                      "default": "An empty object",
                      "desc": "String, finite number, or boolean metadata identifying this benchmark configuration. Parameter keys are sorted when constructing the stable benchmark identity."
                    },
                    {
                      "textRaw": "`samples` {number} The maximum number of measured callback invocations. Must be a positive 32-bit unsigned integer. The benchmark may finish earlier by calling `context.done()`. **Default:** `30`.",
                      "name": "samples",
                      "type": "number",
                      "default": "`30`",
                      "desc": "The maximum number of measured callback invocations. Must be a positive 32-bit unsigned integer. The benchmark may finish earlier by calling `context.done()`."
                    },
                    {
                      "textRaw": "`signal` {AbortSignal} Allows aborting this benchmark.",
                      "name": "signal",
                      "type": "AbortSignal",
                      "desc": "Allows aborting this benchmark."
                    },
                    {
                      "textRaw": "`skip` {boolean|string} If truthy, the benchmark is skipped. A string is included in the result as the skip reason. **Default:** `false`.",
                      "name": "skip",
                      "type": "boolean|string",
                      "default": "`false`",
                      "desc": "If truthy, the benchmark is skipped. A string is included in the result as the skip reason."
                    },
                    {
                      "textRaw": "`tags` {string}[] Labels associated with the benchmark. Tags are lowercased, deduplicated, and inherited from containing suites by union. **Default:** `[]`.",
                      "name": "tags",
                      "type": "string",
                      "default": "`[]`",
                      "desc": "[] Labels associated with the benchmark. Tags are lowercased, deduplicated, and inherited from containing suites by union."
                    },
                    {
                      "textRaw": "`timeout` {number} The number of milliseconds after which the benchmark fails. **Default:** `Infinity`.",
                      "name": "timeout",
                      "type": "number",
                      "default": "`Infinity`",
                      "desc": "The number of milliseconds after which the benchmark fails."
                    },
                    {
                      "textRaw": "`warmup` {number} The number of unreported callback invocations before measured samples. Must be a 32-bit unsigned integer. **Default:** `0`.",
                      "name": "warmup",
                      "type": "number",
                      "default": "`0`",
                      "desc": "The number of unreported callback invocations before measured samples. Must be a 32-bit unsigned integer."
                    }
                  ],
                  "optional": true
                },
                {
                  "textRaw": "`fn` {Function|AsyncFunction} The benchmark function. It receives a {BenchContext}.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "The benchmark function. It receives a {BenchContext}."
                }
              ],
              "return": {
                "textRaw": "Returns: {Promise} Fulfilled with the benchmark result after a top-level benchmark finishes, or with `undefined` immediately when declared in a suite.",
                "name": "return",
                "type": "Promise",
                "desc": "Fulfilled with the benchmark result after a top-level benchmark finishes, or with `undefined` immediately when declared in a suite."
              }
            }
          ],
          "desc": "<p>Warmup invocations use the same callback and timing contract as measured\nsamples, but their samples are discarded. An exception, rejection, timeout,\nabort, missing timing call, or duplicate timing call stops the current\nbenchmark. Later benchmarks continue to run.</p>\n<p>A timeout or abort cannot interrupt synchronous JavaScript and does not forcibly\ncancel asynchronous work that ignores <code>context.signal</code>.</p>\n<p>The stable <code>benchId</code> is based on the source file, hierarchical suite and\nbenchmark names, and canonicalized parameters. Declaring the same identity\nmore than once reports an error rather than merging the samples.</p>",
          "methods": [
            {
              "textRaw": "`bench.skip([name][, options], fn)`",
              "name": "skip",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "name": "name",
                      "optional": true
                    },
                    {
                      "name": "options",
                      "optional": true
                    },
                    {
                      "name": "fn"
                    }
                  ]
                }
              ],
              "desc": "<p>Shorthand for <code>bench(name, { ...options, skip: true }, fn)</code>.</p>"
            },
            {
              "textRaw": "`bench.only([name][, options], fn)`",
              "name": "only",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "name": "name",
                      "optional": true
                    },
                    {
                      "name": "options",
                      "optional": true
                    },
                    {
                      "name": "fn"
                    }
                  ]
                }
              ],
              "desc": "<p>Shorthand for <code>bench(name, { ...options, only: true }, fn)</code>.</p>"
            }
          ]
        },
        {
          "textRaw": "`suite([name][, options], fn)`",
          "name": "suite",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`name` {string} The suite name. **Default:** The `name` property of `fn`, or `'<anonymous>'` when `fn` has no name.",
                  "name": "name",
                  "type": "string",
                  "default": "The `name` property of `fn`, or `'<anonymous>'` when `fn` has no name",
                  "desc": "The suite name.",
                  "optional": true
                },
                {
                  "textRaw": "`options` {Object}",
                  "name": "options",
                  "type": "Object",
                  "options": [
                    {
                      "textRaw": "`only` {boolean} Selects all benchmarks nested in this suite. **Default:** `false`.",
                      "name": "only",
                      "type": "boolean",
                      "default": "`false`",
                      "desc": "Selects all benchmarks nested in this suite."
                    },
                    {
                      "textRaw": "`skip` {boolean|string} Skips all benchmarks nested in this suite. **Default:** `false`.",
                      "name": "skip",
                      "type": "boolean|string",
                      "default": "`false`",
                      "desc": "Skips all benchmarks nested in this suite."
                    },
                    {
                      "textRaw": "`tags` {string}[] Labels inherited by nested suites and benchmarks. **Default:** `[]`.",
                      "name": "tags",
                      "type": "string",
                      "default": "`[]`",
                      "desc": "[] Labels inherited by nested suites and benchmarks."
                    }
                  ],
                  "optional": true
                },
                {
                  "textRaw": "`fn` {Function|AsyncFunction} A function that declares nested suites, benchmarks, and hooks.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "A function that declares nested suites, benchmarks, and hooks."
                }
              ],
              "return": {
                "textRaw": "Returns: {Promise} Fulfilled when a top-level suite finishes, or with `undefined` immediately when declared in another suite.",
                "name": "return",
                "type": "Promise",
                "desc": "Fulfilled when a top-level suite finishes, or with `undefined` immediately when declared in another suite."
              }
            }
          ],
          "desc": "<p>Suite functions run while declarations are collected. Promise-returning suite\nfunctions are awaited before benchmark execution begins.</p>"
        },
        {
          "textRaw": "`describe([name][, options], fn)`",
          "name": "describe",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "name": "name",
                  "optional": true
                },
                {
                  "name": "options",
                  "optional": true
                },
                {
                  "name": "fn"
                }
              ]
            }
          ],
          "desc": "<p>Alias for <code>suite()</code>.</p>"
        },
        {
          "textRaw": "`before(fn)`",
          "name": "before",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`fn` {Function|AsyncFunction} The hook function.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "The hook function."
                }
              ]
            }
          ],
          "desc": "<p>Registers a hook that runs once before the benchmarks in the current suite.</p>"
        },
        {
          "textRaw": "`after(fn)`",
          "name": "after",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`fn` {Function|AsyncFunction} The hook function.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "The hook function."
                }
              ]
            }
          ],
          "desc": "<p>Registers a hook that runs once after the benchmarks in the current suite.</p>"
        },
        {
          "textRaw": "`beforeEach(fn)`",
          "name": "beforeEach",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`fn` {Function|AsyncFunction} The hook function. It receives an object with the benchmark's `name`, `params`, and `signal`.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "The hook function. It receives an object with the benchmark's `name`, `params`, and `signal`."
                }
              ]
            }
          ],
          "desc": "<p>Registers a hook that runs once before each complete logical benchmark in the\ncurrent suite. It does not run before every sample. Per-sample setup belongs in\nthe benchmark function before <code>context.start()</code> or <code>context.record()</code>.</p>"
        },
        {
          "textRaw": "`afterEach(fn)`",
          "name": "afterEach",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`fn` {Function|AsyncFunction} The hook function. It receives an object with the benchmark's `name`, `params`, and `signal`.",
                  "name": "fn",
                  "type": "Function|AsyncFunction",
                  "desc": "The hook function. It receives an object with the benchmark's `name`, `params`, and `signal`."
                }
              ]
            }
          ],
          "desc": "<p>Registers a hook that runs once after each complete logical benchmark in the\ncurrent suite. It does not run after every sample. Per-sample cleanup belongs\nin the benchmark function after <code>context.end()</code> or <code>context.record()</code>.</p>"
        },
        {
          "textRaw": "`run([options])`",
          "name": "run",
          "type": "method",
          "meta": {
            "added": [
              "REPLACEME"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`options` {Object}",
                  "name": "options",
                  "type": "Object",
                  "options": [
                    {
                      "textRaw": "`namePattern` {string|RegExp} Only runs benchmarks whose full hierarchical name matches the pattern. String values are interpreted as JavaScript regular expressions.",
                      "name": "namePattern",
                      "type": "string|RegExp",
                      "desc": "Only runs benchmarks whose full hierarchical name matches the pattern. String values are interpreted as JavaScript regular expressions."
                    },
                    {
                      "textRaw": "`samples` {number} Overrides the maximum number of measured callback invocations for every benchmark. Must be a positive 32-bit unsigned integer.",
                      "name": "samples",
                      "type": "number",
                      "desc": "Overrides the maximum number of measured callback invocations for every benchmark. Must be a positive 32-bit unsigned integer."
                    },
                    {
                      "textRaw": "`signal` {AbortSignal} Allows aborting in-progress benchmark execution.",
                      "name": "signal",
                      "type": "AbortSignal",
                      "desc": "Allows aborting in-progress benchmark execution."
                    },
                    {
                      "textRaw": "`warmup` {number} Overrides the number of unreported warmup callback invocations for every benchmark. Must be a 32-bit unsigned integer.",
                      "name": "warmup",
                      "type": "number",
                      "desc": "Overrides the number of unreported warmup callback invocations for every benchmark. Must be a 32-bit unsigned integer."
                    },
                    {
                      "textRaw": "`yieldBetweenSamples` {boolean} Schedule an event loop turn between sample callbacks. **Default:** `true`, or the value passed to `createRunner()` for an explicit runner.",
                      "name": "yieldBetweenSamples",
                      "type": "boolean",
                      "default": "`true`, or the value passed to `createRunner()` for an explicit runner",
                      "desc": "Schedule an event loop turn between sample callbacks."
                    }
                  ],
                  "optional": true
                }
              ],
              "return": {
                "textRaw": "Returns: {BenchmarksStream}",
                "name": "return",
                "type": "BenchmarksStream"
              }
            }
          ],
          "desc": "<p>Returns the object-mode event stream for the in-process benchmark run. Call\n<code>run()</code> during the same turn in which benchmarks are declared, before automatic\nexecution begins. Calling <code>run()</code> is optional when the returned stream is not\nneeded. An explicit runner created by <code>createRunner()</code> does not run\nautomatically, so its <code>run()</code> function may be called later.</p>\n<pre><code class=\"language-mjs\">import { bench, run } from 'node:bench';\n\nbench('example', { samples: 3 }, (b) => {\n  b.start();\n  doWork();\n  b.end(1);\n});\n\nfor await (const { type, data } of run()) {\n  if (type === 'bench:complete' &#x26;&#x26; data.error === undefined) {\n    console.log(data.name, data.summary.mean);\n  }\n}\n</code></pre>"
        }
      ],
      "classes": [
        {
          "textRaw": "Class: `BenchContext`",
          "name": "BenchContext",
          "type": "class",
          "desc": "<p>An instance of <code>BenchContext</code> is passed to every benchmark invocation. A new\ninstance is created for every warmup and measured sample.</p>",
          "properties": [
            {
              "textRaw": "{number}",
              "name": "index",
              "type": "number",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "desc": "<p>The zero-based invocation index within the current <code>context.phase</code>. Warmup and\nmeasured samples have separate index sequences.</p>"
            },
            {
              "textRaw": "{string}",
              "name": "name",
              "type": "string",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "desc": "<p>The benchmark name.</p>"
            },
            {
              "textRaw": "{Object}",
              "name": "params",
              "type": "Object",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "desc": "<p>The benchmark's canonicalized parameter metadata.</p>"
            },
            {
              "textRaw": "{string}",
              "name": "phase",
              "type": "string",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "desc": "<p>The current sample phase. It is <code>'warmup'</code> for an unreported warmup invocation\nand <code>'measurement'</code> for a measured invocation.</p>"
            },
            {
              "textRaw": "{AbortSignal}",
              "name": "signal",
              "type": "AbortSignal",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "desc": "<p>An abort signal that is triggered when the benchmark is aborted, times out, or\nfinishes.</p>"
            }
          ],
          "methods": [
            {
              "textRaw": "`context.start()`",
              "name": "start",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Starts the measured region using <code>process.hrtime.bigint()</code>. Calling <code>start()</code>\nmore than once is an error.</p>"
            },
            {
              "textRaw": "`context.end(operations[, options])`",
              "name": "end",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`operations` {number} The number of completed operations. Must be a positive safe integer.",
                      "name": "operations",
                      "type": "number",
                      "desc": "The number of completed operations. Must be a positive safe integer."
                    },
                    {
                      "textRaw": "`options` {Object}",
                      "name": "options",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`detail` {any} Additional structured-cloneable sample data. With CLI process isolation, it must also be supported by advanced child process serialization.",
                          "name": "detail",
                          "type": "any",
                          "desc": "Additional structured-cloneable sample data. With CLI process isolation, it must also be supported by advanced child process serialization."
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Object} The sample's `operations`, `duration_ns`, computed `rate`, and optional cloned `detail`.",
                    "name": "return",
                    "type": "Object",
                    "desc": "The sample's `operations`, `duration_ns`, computed `rate`, and optional cloned `detail`."
                  }
                }
              ],
              "desc": "<p>Ends the measured region. The end timestamp is captured before <code>operations</code> is\nvalidated. Calling <code>end()</code> before <code>start()</code>, calling it more than once, or\nrecording a zero-duration sample is an error. When provided, <code>detail</code> is cloned\nafter the end timestamp is captured, so cloning time is outside the measured\nregion.</p>"
            },
            {
              "textRaw": "`context.record(sample)`",
              "name": "record",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`sample` {Object}",
                      "name": "sample",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`operations` {number} The number of completed operations. Must be a positive safe integer.",
                          "name": "operations",
                          "type": "number",
                          "desc": "The number of completed operations. Must be a positive safe integer."
                        },
                        {
                          "textRaw": "`duration_ns` {bigint} An externally measured positive duration in nanoseconds no greater than `Number.MAX_SAFE_INTEGER`.",
                          "name": "duration_ns",
                          "type": "bigint",
                          "desc": "An externally measured positive duration in nanoseconds no greater than `Number.MAX_SAFE_INTEGER`."
                        },
                        {
                          "textRaw": "`detail` {any} Additional structured-cloneable sample data. With CLI process isolation, it must also be supported by advanced child process serialization.",
                          "name": "detail",
                          "type": "any",
                          "desc": "Additional structured-cloneable sample data. With CLI process isolation, it must also be supported by advanced child process serialization."
                        }
                      ]
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Object} The normalized sample, including its computed `rate` and optional cloned `detail`.",
                    "name": "return",
                    "type": "Object",
                    "desc": "The normalized sample, including its computed `rate` and optional cloned `detail`."
                  }
                }
              ],
              "desc": "<p>Records a measurement made by another clock or execution environment. This is\nuseful when a higher-level tool measures work in a worker and needs to exclude\nmessage transport from the duration. <code>record()</code> is mutually exclusive with\n<code>start()</code> and <code>end()</code> within one callback and must be called exactly once.</p>"
            },
            {
              "textRaw": "`context.done()`",
              "name": "done",
              "type": "method",
              "meta": {
                "added": [
                  "REPLACEME"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Requests successful benchmark completion after the current measured sample.\nThe callback must still call either <code>start()</code> and <code>end()</code>, or <code>record()</code>.\nCalling <code>done()</code> during a warmup invocation is an error. The configured\n<code>samples</code> value remains the maximum number of measured invocations if <code>done()</code>\nis not called.</p>"
            }
          ]
        },
        {
          "textRaw": "Class: `BenchmarksStream`",
          "name": "BenchmarksStream",
          "type": "class",
          "desc": "<p><code>BenchmarksStream</code> is an object-mode <a href=\"stream.html#class-streamreadable\"><code>&#x3C;stream.Readable></code></a>. Each lifecycle record is\nboth emitted as a named event and made available on the stream as <code>{ type, data }</code>.</p>\n<p>The events are emitted in execution order:</p>\n<ul>\n<li><code>'bench:start'</code></li>\n<li><code>'bench:sample'</code></li>\n<li><code>'bench:complete'</code></li>\n<li><code>'bench:diagnostic'</code></li>\n<li><code>'bench:summary'</code></li>\n</ul>\n<p>Every benchmark-scoped event contains <code>benchId</code> and <code>parentId</code>.\n<code>'bench:complete'</code> data contains a <a href=\"#benchmark-result\">benchmark result</a>. A failed result has an\nadditional <code>error</code> property and may contain samples recorded before the error.\nA skipped result has an additional <code>skip</code> property and an empty <code>samples</code>\narray. <code>'bench:diagnostic'</code> reports suite and hook errors. <code>'bench:summary'</code>\ncontains overall <code>success</code>, <code>counts</code>, <code>duration_ns</code>, and <code>file</code> properties. The\n<code>file</code> is <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#null_type\"><code>&#x3C;null></code></a>; it is <code>null</code> when the summary aggregates multiple\nfiles.</p>"
        }
      ],
      "displayName": "Benchmark runner"
    }
  ]
}