From dde0cffb2e80302a82f562b91f029205a5e1097b Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Fri, 29 Mar 2024 19:40:22 -0300 Subject: [PATCH] benchmark: add toNamespacedPath bench MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/52236 Reviewed-By: Yagiz Nizipli Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Luigi Pinca --- benchmark/path/toNamespacedPath-posix.js | 26 ++++++++++++++++++++++ benchmark/path/toNamespacedPath-win32.js | 28 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 benchmark/path/toNamespacedPath-posix.js create mode 100644 benchmark/path/toNamespacedPath-win32.js diff --git a/benchmark/path/toNamespacedPath-posix.js b/benchmark/path/toNamespacedPath-posix.js new file mode 100644 index 00000000000000..dbef737dc8ee84 --- /dev/null +++ b/benchmark/path/toNamespacedPath-posix.js @@ -0,0 +1,26 @@ +'use strict'; +const common = require('../common.js'); +const { posix } = require('path'); +const assert = require('assert'); + +const bench = common.createBenchmark(main, { + path: [ + '', + '.', + '/tmp/bar', + '/home/node/..', + posix.join(__dirname, '/..'), + 'bar/baz', + ], + n: [1e5], +}); + +function main({ n, path }) { + bench.start(); + let a; + for (let i = 0; i < n; i++) { + a = posix.toNamespacedPath(path); + } + bench.end(n); + assert.ok(a + 'a'); +} diff --git a/benchmark/path/toNamespacedPath-win32.js b/benchmark/path/toNamespacedPath-win32.js new file mode 100644 index 00000000000000..7cb38bf63aebf0 --- /dev/null +++ b/benchmark/path/toNamespacedPath-win32.js @@ -0,0 +1,28 @@ +'use strict'; +const common = require('../common.js'); +const { win32 } = require('path'); +const assert = require('assert'); + +const bench = common.createBenchmark(main, { + path: [ + '', + 'c:/ignore', + 'd:\\a/b\\c/d', + '\\e.exe', + 'c:/blah\\blah', + 'd:/games', + 'c:../a', + win32.join(__dirname, '/..'), + ], + n: [1e5], +}); + +function main({ n, path }) { + bench.start(); + let a; + for (let i = 0; i < n; i++) { + a = win32.toNamespacedPath(path); + } + bench.end(n); + assert.ok(a + 'a'); +}