GeezerVison is showing github.com — lib: put node:bench behind an --experimental-bench flag · nodejs/node@7575fec
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: benchmark/_node-bench.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,6 +53,7 @@ function runBenchmark(binary, file, options) { | 53 | 53 | const args = [ | 54 | 54 | ...options.nodeArgs, | 55 | 55 | '--no-warnings', | | 56 | + '--experimental-bench', | 56 | 57 | '--bench', | 57 | 58 | '--bench-reporter=json', | 58 | 59 | '--bench-samples=1', | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/bench.md +5-6Lines changed: 5 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,8 @@ added: REPLACEME | 12 | 12 |
| 13 | 13 | The `node:bench` module supports defining and running JavaScript benchmarks in | 14 | 14 | the current process, and running one benchmark file in a fresh child process. | 15 | | -To access it: | | 15 | +The module is only available when Node.js is started with the | | 16 | +`--experimental-bench` flag and can only be imported with the `node:` scheme: | 16 | 17 |
| 17 | 18 | ```mjs | 18 | 19 | import { bench, suite } from 'node:bench'; | @@ -22,8 +23,6 @@ import { bench, suite } from 'node:bench'; | 22 | 23 | const { bench, suite } = require('node:bench'); | 23 | 24 | ``` | 24 | 25 |
| 25 | | -This module is only available under the `node:` scheme. | 26 | | - | 27 | 26 | ## Example benchmark | 28 | 27 |
| 29 | 28 | Save the following as `benchmark.mjs`: | @@ -57,7 +56,7 @@ suite('URL', () => { | 57 | 56 | Run the benchmark from the command line: | 58 | 57 |
| 59 | 58 | ```console | 60 | | -node --bench benchmark.mjs | | 59 | +node --experimental-bench --bench benchmark.mjs | 61 | 60 | ``` | 62 | 61 |
| 63 | 62 | Benchmarks are executed serially in declaration order. Declared benchmarks are | @@ -183,8 +182,8 @@ declarations and a second call to `run()` is an error. | 183 | 182 | The `--bench` flag runs one or more explicit benchmark files or glob patterns: | 184 | 183 |
| 185 | 184 | ```console | 186 | | -node --bench benchmark.mjs | 187 | | -node --bench --bench-reporter=json 'benchmarks/**/*.js' | | 185 | +node --experimental-bench --bench benchmark.mjs | | 186 | +node --experimental-bench --bench --bench-reporter=json 'benchmarks/**/*.js' | 188 | 187 | ``` | 189 | 188 |
| 190 | 189 | Files are sorted and executed serially. The default | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +16-2Lines changed: 16 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -482,10 +482,13 @@ Starts the Node.js command-line benchmark runner. At least one explicit file or | 482 | 482 | glob pattern is required: | 483 | 483 |
| 484 | 484 | ```console | 485 | | -node --bench benchmark.mjs | 486 | | -node --bench 'benchmarks/**/*.js' | | 485 | +node --experimental-bench --bench benchmark.mjs | | 486 | +node --experimental-bench --bench 'benchmarks/**/*.js' | 487 | 487 | ``` | 488 | 488 |
| | 489 | +The `--experimental-bench` flag is required to use this flag or any other | | 490 | +`--bench-*` option. | | 491 | + | 489 | 492 | Quote glob patterns to prevent expansion by the shell. Matching files are | 490 | 493 | sorted and executed serially. By default, each file runs in a separate child | 491 | 494 | process. Benchmark files declare benchmarks using `node:bench`; they must not | @@ -1215,6 +1218,16 @@ changes: | 1215 | 1218 |
| 1216 | 1219 | Enable experimental import support for `.node` addons. | 1217 | 1220 |
| | 1221 | +### `--experimental-bench` | | 1222 | + | | 1223 | +<!-- YAML | | 1224 | +added: REPLACEME | | 1225 | +--> | | 1226 | + | | 1227 | +> Stability: 1 - Experimental | | 1228 | +
| | 1229 | +Enable the experimental `node:bench` module and command-line benchmark runner. | | 1230 | + | 1218 | 1231 | ### `--experimental-config-file=path`, `--experimental-config-file` | 1219 | 1232 |
| 1220 | 1233 | <!-- YAML | @@ -4074,6 +4087,7 @@ one is included in the list below. | 4074 | 4087 | * `--entry-url` | 4075 | 4088 | * `--experimental-abortcontroller` | 4076 | 4089 | * `--experimental-addon-modules` | | 4090 | +* `--experimental-bench` | 4077 | 4091 | * `--experimental-detect-module` | 4078 | 4092 | * `--experimental-dtls` | 4079 | 4093 | * `--experimental-eventsource` | |
Collapse file Copy file name to clipboardExpand all lines: doc/node-config-schema.json +107Lines changed: 107 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 45 | 45 | "$schema": { | 46 | 46 | "type": "string" | 47 | 47 | }, | | 48 | + "bench": { | | 49 | + "type": "object", | | 50 | + "additionalProperties": false, | | 51 | + "required": [], | | 52 | + "properties": { | | 53 | + "bench": { | | 54 | + "type": "boolean", | | 55 | + "description": "launch benchmark runner on startup" | | 56 | + }, | | 57 | + "bench-isolation": { | | 58 | + "type": "string", | | 59 | + "description": "configures the type of benchmark isolation used in the benchmark runner" | | 60 | + }, | | 61 | + "bench-name-pattern": { | | 62 | + "type": "string", | | 63 | + "description": "run benchmarks whose name matches this regular expression" | | 64 | + }, | | 65 | + "bench-reporter": { | | 66 | + "oneOf": [ | | 67 | + { | | 68 | + "type": "string" | | 69 | + }, | | 70 | + { | | 71 | + "type": "array", | | 72 | + "minItems": 1, | | 73 | + "items": { | | 74 | + "type": "string" | | 75 | + } | | 76 | + } | | 77 | + ], | | 78 | + "description": "report benchmark output using the given reporter" | | 79 | + }, | | 80 | + "bench-reporter-destination": { | | 81 | + "oneOf": [ | | 82 | + { | | 83 | + "type": "string" | | 84 | + }, | | 85 | + { | | 86 | + "type": "array", | | 87 | + "minItems": 1, | | 88 | + "items": { | | 89 | + "type": "string" | | 90 | + } | | 91 | + } | | 92 | + ], | | 93 | + "description": "report the given benchmark reporter to the given destination" | | 94 | + }, | | 95 | + "bench-samples": { | | 96 | + "type": "number", | | 97 | + "description": "specify the number of measured benchmark samples" | | 98 | + }, | | 99 | + "bench-warmup": { | | 100 | + "type": "number", | | 101 | + "description": "specify the number of unreported benchmark warmup samples" | | 102 | + } | | 103 | + } | | 104 | + }, | 48 | 105 | "nodeOptions": { | 49 | 106 | "additionalProperties": false, | 50 | 107 | "required": [], | | 119 | 176 | "type": "boolean", | 120 | 177 | "description": "Improve AsyncLocalStorage performance with AsyncContextFrame" | 121 | 178 | }, | | 179 | + "bench-isolation": { | | 180 | + "type": "string", | | 181 | + "description": "configures the type of benchmark isolation used in the benchmark runner" | | 182 | + }, | | 183 | + "bench-name-pattern": { | | 184 | + "type": "string", | | 185 | + "description": "run benchmarks whose name matches this regular expression" | | 186 | + }, | | 187 | + "bench-reporter": { | | 188 | + "oneOf": [ | | 189 | + { | | 190 | + "type": "string" | | 191 | + }, | | 192 | + { | | 193 | + "type": "array", | | 194 | + "minItems": 1, | | 195 | + "items": { | | 196 | + "type": "string" | | 197 | + } | | 198 | + } | | 199 | + ], | | 200 | + "description": "report benchmark output using the given reporter" | | 201 | + }, | | 202 | + "bench-reporter-destination": { | | 203 | + "oneOf": [ | | 204 | + { | | 205 | + "type": "string" | | 206 | + }, | | 207 | + { | | 208 | + "type": "array", | | 209 | + "minItems": 1, | | 210 | + "items": { | | 211 | + "type": "string" | | 212 | + } | | 213 | + } | | 214 | + ], | | 215 | + "description": "report the given benchmark reporter to the given destination" | | 216 | + }, | | 217 | + "bench-samples": { | | 218 | + "type": "number", | | 219 | + "description": "specify the number of measured benchmark samples" | | 220 | + }, | | 221 | + "bench-warmup": { | | 222 | + "type": "number", | | 223 | + "description": "specify the number of unreported benchmark warmup samples" | | 224 | + }, | 122 | 225 | "conditions": { | 123 | 226 | "oneOf": [ | 124 | 227 | { | | 209 | 312 | "type": "boolean", | 210 | 313 | "description": "experimental import support for addons" | 211 | 314 | }, | | 315 | + "experimental-bench": { | | 316 | + "type": "boolean", | | 317 | + "description": "experimental node:bench module and benchmark runner" | | 318 | + }, | 212 | 319 | "experimental-detect-module": { | 213 | 320 | "type": "boolean", | 214 | 321 | "description": "when ambiguous modules fail to evaluate because they contain ES module syntax, try again to evaluate them as ES modules" | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -296,9 +296,11 @@ Error: Access to this API has been restricted | 296 | 296 | Starts the Node.js command-line benchmark runner. At least one explicit file or | 297 | 297 | glob pattern is required: | 298 | 298 | .Bd -literal | 299 | | -node --bench benchmark.mjs | 300 | | -node --bench 'benchmarks/**/*.js' | | 299 | +node --experimental-bench --bench benchmark.mjs | | 300 | +node --experimental-bench --bench 'benchmarks/**/*.js' | 301 | 301 | .Ed | | 302 | +The \fB--experimental-bench\fR flag is required to use this flag or any other | | 303 | +\fB--bench-*\fR option. | 302 | 304 | Quote glob patterns to prevent expansion by the shell. Matching files are | 303 | 305 | sorted and executed serially. By default, each file runs in a separate child | 304 | 306 | process. Benchmark files declare benchmarks using \fBnode:bench\fR; they must not | @@ -677,6 +679,9 @@ It is possible to run code containing inline types unless the | 677 | 679 | .It Fl -experimental-addon-modules | 678 | 680 | Enable experimental import support for \fB.node\fR addons. | 679 | 681 | . | | 682 | +.It Fl -experimental-bench | | 683 | +Enable the experimental \fBnode:bench\fR module and command-line benchmark runner. | | 684 | +. | 680 | 685 | .It Fl -experimental-config-file Ns = Ns Ar path , Fl -experimental-config-file | 681 | 686 | If present, Node.js will look for a configuration file at the specified path. | 682 | 687 | If the path is not specified, Node.js will look for a \fBnode.config.json\fR file | @@ -2092,6 +2097,8 @@ one is included in the list below. | 2092 | 2097 | .It | 2093 | 2098 | \fB--experimental-addon-modules\fR | 2094 | 2099 | .It | | 2100 | +\fB--experimental-bench\fR | | 2101 | +.It | 2095 | 2102 | \fB--experimental-detect-module\fR | 2096 | 2103 | .It | 2097 | 2104 | \fB--experimental-dtls\fR | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bench_runner/cli.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,7 +106,11 @@ const kEventTypes = new SafeSet([ | 106 | 106 | 'bench:diagnostic', | 107 | 107 | 'bench:summary', | 108 | 108 | ]); | 109 | | -const kFilterArgs = ['--bench', '--experimental-default-config-file']; | | 109 | +const kFilterArgs = [ | | 110 | + '--bench', | | 111 | + '--experimental-bench', | | 112 | + '--experimental-default-config-file', | | 113 | +]; | 110 | 114 | const kFilterArgValues = [ | 111 | 115 | '--bench-isolation', | 112 | 116 | '--bench-name-pattern', | @@ -741,7 +745,8 @@ function getInheritedChildArgs() { | 741 | 745 | function getChildArgs(path, options) { | 742 | 746 | const args = options.execArgv === undefined ? | 743 | 747 | getInheritedChildArgs() : ArrayPrototypeSlice(options.execArgv); | 744 | | - ArrayPrototypePush(args, '--bench', '--bench-isolation=none'); | | 748 | + ArrayPrototypePush( | | 749 | + args, '--experimental-bench', '--bench', '--bench-isolation=none'); | 745 | 750 | if (options.namePatternSource.length > 0) { | 746 | 751 | ArrayPrototypePush( | 747 | 752 | args, `--bench-name-pattern=${options.namePatternSource}`); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/realm.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,6 +137,8 @@ const schemelessBlockList = new SafeSet([ | 137 | 137 | ]); | 138 | 138 | // Modules that will only be enabled at run time. | 139 | 139 | const experimentalModuleList = new SafeSet([ | | 140 | + 'bench', | | 141 | + 'bench/reporters', | 140 | 142 | 'dtls', | 141 | 143 | 'ffi', | 142 | 144 | 'quic', | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -114,6 +114,7 @@ function prepareExecution(options) { | 114 | 114 | setupNetworkInspection(); | 115 | 115 | setupNavigator(); | 116 | 116 | setupWarningHandler(); | | 117 | + setupBench(); | 117 | 118 | setupFFI(); | 118 | 119 | setupSQLite(); | 119 | 120 | setupStreamIter(); | @@ -382,6 +383,16 @@ function setupNavigator() { | 382 | 383 | defineReplaceableLazyAttribute(globalThis, 'internal/navigator', ['navigator'], false); | 383 | 384 | } | 384 | 385 |
| | 386 | +function setupBench() { | | 387 | + if (!getOptionValue('--experimental-bench')) { | | 388 | + return; | | 389 | + } | | 390 | + | | 391 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | | 392 | + BuiltinModule.allowRequireByUsers('bench'); | | 393 | + BuiltinModule.allowRequireByUsers('bench/reporters'); | | 394 | +} | | 395 | + | 385 | 396 | function setupFFI() { | 386 | 397 | if (!getOptionValue('--experimental-ffi')) { | 387 | 398 | return; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_builtins.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -158,6 +158,8 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const { | 158 | 158 | #if !HAVE_FFI | 159 | 159 | "internal/ffi-shared-buffer", "internal/ffi/fast-api", | 160 | 160 | #endif // !HAVE_FFI | | 161 | + "bench", // Experimental. | | 162 | + "bench/reporters", // Experimental. | 161 | 163 | "dtls", // Experimental. | 162 | 164 | "ffi", // Experimental. | 163 | 165 | "quic", // Experimental. | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -243,6 +243,11 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors, | 243 | 243 | errors->push_back("invalid value for --trace-require-module"); | 244 | 244 | } | 245 | 245 |
| | 246 | + if (has_bench_options && !experimental_bench) { | | 247 | + errors->push_back( | | 248 | + "--experimental-bench is required to use --bench or related options"); | | 249 | + } | | 250 | + | 246 | 251 | if (bench_runner && test_runner) { | 247 | 252 | errors->push_back("either --bench or --test can be used, not both"); | 248 | 253 | } | @@ -632,6 +637,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 632 | 637 | "experimental import support for addons", | 633 | 638 | BOOL_FIELD(experimental_addon_modules), | 634 | 639 | kAllowedInEnvvar); | | 640 | + AddOption("--experimental-bench", | | 641 | + "experimental node:bench module and benchmark runner", | | 642 | + BOOL_FIELD(experimental_bench), | | 643 | + kAllowedInEnvvar); | 635 | 644 | AddOption("--experimental-abortcontroller", "", NoOp{}, kAllowedInEnvvar); | 636 | 645 | AddOption("--experimental-eventsource", | 637 | 646 | "experimental EventSource API", | @@ -985,40 +994,47 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 985 | 994 | "use the specified file for package map resolution", | 986 | 995 | &EnvironmentOptions::experimental_package_map_path, | 987 | 996 | kAllowedInEnvvar); | | 997 | + AddOption("[has_bench_options]", "", BOOL_FIELD(has_bench_options)); | 988 | 998 | AddOption("--bench", | 989 | 999 | "launch benchmark runner on startup", | 990 | 1000 | BOOL_FIELD(bench_runner), | 991 | 1001 | kDisallowedInEnvvar, | 992 | 1002 | false, | 993 | 1003 | OptionNamespaces::kBenchRunnerNamespace); | | 1004 | + Implies("--bench", "[has_bench_options]"); | 994 | 1005 | AddOption("--bench-isolation", | 995 | 1006 | "configures the type of benchmark isolation used in the benchmark " | 996 | 1007 | "runner", | 997 | 1008 | &EnvironmentOptions::bench_isolation, | 998 | 1009 | kAllowedInEnvvar, | 999 | 1010 | OptionNamespaces::kBenchRunnerNamespace); | | 1011 | + Implies("--bench-isolation", "[has_bench_options]"); | 1000 | 1012 | AddOption("--bench-name-pattern", | 1001 | 1013 | "run benchmarks whose name matches this regular expression", | 1002 | 1014 | &EnvironmentOptions::bench_name_pattern, | 1003 | 1015 | kAllowedInEnvvar, | 1004 | 1016 | OptionNamespaces::kBenchRunnerNamespace); | | 1017 | + Implies("--bench-name-pattern", "[has_bench_options]"); | 1005 | 1018 | AddOption("--bench-reporter", | 1006 | 1019 | "report benchmark output using the given reporter", | 1007 | 1020 | &EnvironmentOptions::bench_reporter, | 1008 | 1021 | kAllowedInEnvvar, | 1009 | 1022 | OptionNamespaces::kBenchRunnerNamespace); | | 1023 | + Implies("--bench-reporter", "[has_bench_options]"); | 1010 | 1024 | AddOption("--bench-reporter-destination", | 1011 | 1025 | "report the given benchmark reporter to the given destination", | 1012 | 1026 | &EnvironmentOptions::bench_reporter_destination, | 1013 | 1027 | kAllowedInEnvvar, | 1014 | 1028 | OptionNamespaces::kBenchRunnerNamespace); | | 1029 | + Implies("--bench-reporter-destination", "[has_bench_options]"); | 1015 | 1030 | AddOption("[has_bench_samples]", "", BOOL_FIELD(has_bench_samples)); | 1016 | 1031 | AddOption("--bench-samples", | 1017 | 1032 | "specify the number of measured benchmark samples", | 1018 | 1033 | &EnvironmentOptions::bench_samples, | 1019 | 1034 | kAllowedInEnvvar, | 1020 | 1035 | OptionNamespaces::kBenchRunnerNamespace, | 1021 | 1036 | kStrictOptionParsing); | | 1037 | + Implies("--bench-samples", "[has_bench_options]"); | 1022 | 1038 | Implies("--bench-samples", "[has_bench_samples]"); | 1023 | 1039 | AddOption("[has_bench_warmup]", "", BOOL_FIELD(has_bench_warmup)); | 1024 | 1040 | AddOption("--bench-warmup", | @@ -1027,6 +1043,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 1027 | 1043 | kAllowedInEnvvar, | 1028 | 1044 | OptionNamespaces::kBenchRunnerNamespace, | 1029 | 1045 | kStrictOptionParsing); | | 1046 | + Implies("--bench-warmup", "[has_bench_options]"); | 1030 | 1047 | Implies("--bench-warmup", "[has_bench_warmup]"); | 1031 | 1048 | AddOption("--test", | 1032 | 1049 | "launch test runner on startup", | |
|