From 3b40fafca131c4a7b27e178050734b5f0f0ef4b8 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 27 Dec 2025 10:16:56 +0300 Subject: [PATCH 1/4] benchmark: add benchmark utility for isNativeError function --- benchmark/util/is-native-error.js | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 benchmark/util/is-native-error.js diff --git a/benchmark/util/is-native-error.js b/benchmark/util/is-native-error.js new file mode 100644 index 00000000000000..480461670b7ac8 --- /dev/null +++ b/benchmark/util/is-native-error.js @@ -0,0 +1,35 @@ +'use strict'; + +const common = require('../common'); + +const args = { + true: new Error('test'), + falsePrimitive: 42, + falseObject: { foo: 'bar' }, +}; + +const bench = common.createBenchmark( + main, + { + argument: ['true', 'falsePrimitive', 'falseObject'], + version: ['native', 'js'], + n: [1e6], + }, + { + flags: ['--expose-internals', '--no-warnings'], + }, +); + +function main({ argument, version, n }) { + const util = common.binding('util'); + const types = require('internal/util/types'); + + const func = { native: util, js: types }[version].isNativeError; + const arg = args[argument]; + + bench.start(); + for (let iteration = 0; iteration < n; iteration++) { + func(arg); + } + bench.end(n); +} From 5fcf423cf6d0bfc6007a54e899376f91ba9662f1 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 27 Dec 2025 19:41:45 +0300 Subject: [PATCH 2/4] repair benchmark --- benchmark/util/is-native-error.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/benchmark/util/is-native-error.js b/benchmark/util/is-native-error.js index 480461670b7ac8..29ff42c996bc1d 100644 --- a/benchmark/util/is-native-error.js +++ b/benchmark/util/is-native-error.js @@ -25,11 +25,15 @@ function main({ argument, version, n }) { const types = require('internal/util/types'); const func = { native: util, js: types }[version].isNativeError; - const arg = args[argument]; + + const testArgs = [args[argument], args[argument], args[argument]]; + let sum = 0; bench.start(); for (let iteration = 0; iteration < n; iteration++) { - func(arg); + const testArg = testArgs[iteration % 3]; + sum += func(testArg) ? 1 : 0; } bench.end(n); + if (sum < 0) console.log(sum); } From 9de3f6fecd0fe04dbaa7570ff56ac9ca6dd2b47c Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sun, 28 Dec 2025 10:55:04 +0300 Subject: [PATCH 3/4] refine test arguments and measure elapsed time in isNativeError benchmark --- benchmark/util/is-native-error.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/benchmark/util/is-native-error.js b/benchmark/util/is-native-error.js index 29ff42c996bc1d..86db9c29439585 100644 --- a/benchmark/util/is-native-error.js +++ b/benchmark/util/is-native-error.js @@ -26,14 +26,15 @@ function main({ argument, version, n }) { const func = { native: util, js: types }[version].isNativeError; - const testArgs = [args[argument], args[argument], args[argument]]; - let sum = 0; + const testArgs = [args.true, args.falsePrimitive, args.falseObject]; bench.start(); + const start = performance.now(); for (let iteration = 0; iteration < n; iteration++) { - const testArg = testArgs[iteration % 3]; - sum += func(testArg) ? 1 : 0; + const testArg = testArgs[iteration % testArgs.length]; + func(testArg); } + const end = performance.now(); bench.end(n); - if (sum < 0) console.log(sum); + console.log('Elapsed(ms):', (end - start).toFixed(3)); } From c4aaa5daee5a78e93f553d147db46139e7f84e8b Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sun, 28 Dec 2025 14:38:40 +0300 Subject: [PATCH 4/4] simplify isNativeError test arguments and remove performance logging --- benchmark/util/is-native-error.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/benchmark/util/is-native-error.js b/benchmark/util/is-native-error.js index 86db9c29439585..665c436bab80b4 100644 --- a/benchmark/util/is-native-error.js +++ b/benchmark/util/is-native-error.js @@ -11,8 +11,8 @@ const args = { const bench = common.createBenchmark( main, { - argument: ['true', 'falsePrimitive', 'falseObject'], - version: ['native', 'js'], + argument: ['true'], + version: ['native'], n: [1e6], }, { @@ -25,16 +25,11 @@ function main({ argument, version, n }) { const types = require('internal/util/types'); const func = { native: util, js: types }[version].isNativeError; - - const testArgs = [args.true, args.falsePrimitive, args.falseObject]; + const arg = args[argument]; bench.start(); - const start = performance.now(); for (let iteration = 0; iteration < n; iteration++) { - const testArg = testArgs[iteration % testArgs.length]; - func(testArg); + func(arg); } - const end = performance.now(); bench.end(n); - console.log('Elapsed(ms):', (end - start).toFixed(3)); }