Skip to content

Commit b9a56e7

Browse files
committed
benchmark: ensure integer division in http headers benchmark
1 parent b2e74dd commit b9a56e7

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

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
@@ -707,3 +707,59 @@ Supported options keys are:
707707
[node-benchmark-compare]: https://github.com/targos/node-benchmark-compare
708708
[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
709709
[wrk]: https://github.com/wg/wrk
710+
711+
### Creating Benchmark Tests
712+
713+
It is recommended to create a new test file when a new benchmark is introduced
714+
so it can be easily made creating the new test file in `test/benchmark`.
715+
716+
When calling the `runBenchmark`, provide the benchmark group name
717+
(which is the folder name in the `benchmark/` folder) as the first parameter,
718+
and optionally pass environment variables as the second parameter.
719+
720+
```js
721+
'use strict';
722+
723+
require('../common'); // Import the common module - required for all benchmark files
724+
725+
const runBenchmark = require('../common/benchmark');
726+
727+
runBenchmark('buffers', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
728+
```
729+
730+
The environment variable `NODEJS_BENCHMARK_ZERO_ALLOWED` is required
731+
when tests execute so quickly that they may produce errors or inconsistent results.
732+
Setting this variable instructs the benchmark to disregard such issues.
733+
734+
Test execution behavior depends on the `NODE_RUN_ALL_BENCH_TESTS` environment variable.
735+
When set to **true**, benchmarks run with minimal iterations (`n=1`, `rounds=1`).
736+
This approach bypasses performance analysis to verify that tests can complete without failures.
737+
Despite the minimal iterations, execution remains time-consuming
738+
as all configurations must be tested.
739+
740+
When `NODE_RUN_ALL_BENCH_TESTS` is not set,
741+
only a single configuration per benchmark executes.
742+
While this dramatically reduces execution time, it provides limited coverage
743+
and cannot guarantee that all configurations function properly.
744+
745+
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.
746+
This PR also documents how to write benchmark tests and provides more details about the environment variables:
747+
748+
* NODE_RUN_ALL_BENCH_TESTS
749+
* NODEJS_BENCHMARK_ZERO_ALLOWED
750+
751+
Benchmark tests were added for the following groups:
752+
753+
* abort_controller
754+
* error
755+
* https
756+
* perf_hooks
757+
* permission
758+
* sqlite
759+
* test_runner
760+
* websocket
761+
762+
Additionally, some inconsistent test files were renamed:
763+
764+
test/benchmark/test-benchmark-async-hooks.js → test/benchmark/test-benchmark-async_hooks.js
765+
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)