Skip to content

Commit 668997f

Browse files
committed
benchmark: ensure integer division in http headers benchmark
1 parent 7a5ff10 commit 668997f

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

benchmark/http/headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main({ len, n, duration }) {
2727
'Transfer-Encoding': 'chunked',
2828
};
2929

30-
const Is = [...Array(n / len).keys()];
30+
const Is = [...Array(parseInt(n / len)).keys()];
3131
const Js = [...Array(len).keys()];
3232

3333
for (const i of Is) {

doc/contributing/writing-and-running-benchmarks.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,59 @@ Supported options keys are:
742742
[node-benchmark-compare]: https://github.com/targos/node-benchmark-compare
743743
[t-test]: https://en.wikipedia.org/wiki/Student%27s_t-test#Equal_or_unequal_sample_sizes%2C_unequal_variances_%28sX1_%3E_2sX2_or_sX2_%3E_2sX1%29
744744
[wrk]: https://github.com/wg/wrk
745+
746+
### Creating Benchmark Tests
747+
748+
It is recommended to create a new test file when a new benchmark is introduced
749+
so it can be easily made creating the new test file in `test/benchmark`.
750+
751+
When calling the `runBenchmark`, provide the benchmark group name
752+
(which is the folder name in the `benchmark/` folder) as the first parameter,
753+
and optionally pass environment variables as the second parameter.
754+
755+
```js
756+
'use strict';
757+
758+
require('../common'); // Import the common module - required for all benchmark files
759+
760+
const runBenchmark = require('../common/benchmark');
761+
762+
runBenchmark('buffers', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
763+
```
764+
765+
The environment variable `NODEJS_BENCHMARK_ZERO_ALLOWED` is required
766+
when tests execute so quickly that they may produce errors or inconsistent results.
767+
Setting this variable instructs the benchmark to disregard such issues.
768+
769+
Test execution behavior depends on the `NODE_RUN_ALL_BENCH_TESTS` environment variable.
770+
When set to **true**, benchmarks run with minimal iterations (`n=1`, `rounds=1`).
771+
This approach bypasses performance analysis to verify that tests can complete without failures.
772+
Despite the minimal iterations, execution remains time-consuming
773+
as all configurations must be tested.
774+
775+
When `NODE_RUN_ALL_BENCH_TESTS` is not set,
776+
only a single configuration per benchmark executes.
777+
While this dramatically reduces execution time, it provides limited coverage
778+
and cannot guarantee that all configurations function properly.
779+
780+
This PR introduces the usage of a new environment variable `NODE_RUN_ALL_BENCH_TESTS`, which can be set to run all benchmark configurations in tests to cover more scenarios where benchmarks might fail.
781+
This PR also documents how to write benchmark tests and provides more details about the environment variables:
782+
783+
* NODE_RUN_ALL_BENCH_TESTS
784+
* NODEJS_BENCHMARK_ZERO_ALLOWED
785+
786+
Benchmark tests were added for the following groups:
787+
788+
* abort_controller
789+
* error
790+
* https
791+
* perf_hooks
792+
* permission
793+
* sqlite
794+
* test_runner
795+
* websocket
796+
797+
Additionally, some inconsistent test files were renamed:
798+
799+
test/benchmark/test-benchmark-async-hooks.js → test/benchmark/test-benchmark-async_hooks.js
800+
test/benchmark/test-benchmark-child-process.js → test/benchmark/test-benchmark-child_process.js

test/benchmark/test-benchmark-test_runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ require('../common');
44

55
const runBenchmark = require('../common/benchmark');
66

7-
runBenchmark('test_runner')
7+
runBenchmark('test_runner');

0 commit comments

Comments
 (0)