summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-12-30 00:26:36 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-05 01:22:22 +0100
commit038a1a489d6d0a4d5c075611943b3c7c08f0e22a (patch)
tree6fce510b11ad12351d9c23dd241e5bbdfb59b122 /benchmark
parent955be8623d58566849cf6a59ff82e78cf14f239a (diff)
downloadandroid-node-v8-038a1a489d6d0a4d5c075611943b3c7c08f0e22a.tar.gz
android-node-v8-038a1a489d6d0a4d5c075611943b3c7c08f0e22a.tar.bz2
android-node-v8-038a1a489d6d0a4d5c075611943b3c7c08f0e22a.zip
benchmark: refactor path benchmarks
So far the benchmarks created a highly specialized function which would inline exactly to the input. This changes it to provide a more realistic view to actual input by changing the input on each iteration. That prevents the function to be to specific. It also reduces the number of iterations the benchmarks are run to reduce the overall runtime. A microbenchmark should already show a significant difference with lower iterations, otherwise the significance for real world applications is only limited. PR-URL: https://github.com/nodejs/node/pull/26359 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/path/basename-posix.js4
-rw-r--r--benchmark/path/basename-win32.js4
-rw-r--r--benchmark/path/dirname-posix.js4
-rw-r--r--benchmark/path/dirname-win32.js4
-rw-r--r--benchmark/path/extname-posix.js4
-rw-r--r--benchmark/path/extname-win32.js4
-rw-r--r--benchmark/path/format-posix.js8
-rw-r--r--benchmark/path/format-win32.js8
-rw-r--r--benchmark/path/isAbsolute-posix.js4
-rw-r--r--benchmark/path/isAbsolute-win32.js4
-rw-r--r--benchmark/path/join-posix.js11
-rw-r--r--benchmark/path/join-win32.js11
-rw-r--r--benchmark/path/makeLong-win32.js4
-rw-r--r--benchmark/path/normalize-posix.js4
-rw-r--r--benchmark/path/normalize-win32.js4
-rw-r--r--benchmark/path/parse-posix.js9
-rw-r--r--benchmark/path/parse-win32.js9
-rw-r--r--benchmark/path/relative-posix.js12
-rw-r--r--benchmark/path/relative-win32.js14
-rw-r--r--benchmark/path/resolve-posix.js11
-rw-r--r--benchmark/path/resolve-win32.js11
21 files changed, 86 insertions, 62 deletions
diff --git a/benchmark/path/basename-posix.js b/benchmark/path/basename-posix.js
index 024687cef0..45cad1e256 100644
--- a/benchmark/path/basename-posix.js
+++ b/benchmark/path/basename-posix.js
@@ -15,7 +15,7 @@ const bench = common.createBenchmark(main, {
'/foo/bar/baz/asdf/quux.html',
['/foo/bar/baz/asdf/quux.html', '.html'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, pathext }) {
@@ -28,7 +28,7 @@ function main({ n, pathext }) {
bench.start();
for (var i = 0; i < n; i++) {
- posix.basename(pathext, ext);
+ posix.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
}
bench.end(n);
}
diff --git a/benchmark/path/basename-win32.js b/benchmark/path/basename-win32.js
index a68bf0c12a..30d65f3ac6 100644
--- a/benchmark/path/basename-win32.js
+++ b/benchmark/path/basename-win32.js
@@ -15,7 +15,7 @@ const bench = common.createBenchmark(main, {
'\\foo\\bar\\baz\\asdf\\quux.html',
['\\foo\\bar\\baz\\asdf\\quux.html', '.html'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, pathext }) {
@@ -28,7 +28,7 @@ function main({ n, pathext }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32.basename(pathext, ext);
+ win32.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
}
bench.end(n);
}
diff --git a/benchmark/path/dirname-posix.js b/benchmark/path/dirname-posix.js
index b99bb99b3b..93f2f32c01 100644
--- a/benchmark/path/dirname-posix.js
+++ b/benchmark/path/dirname-posix.js
@@ -12,13 +12,13 @@ const bench = common.createBenchmark(main, {
'foo/bar',
'/foo/bar/baz/asdf/quux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- posix.dirname(path);
+ posix.dirname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/dirname-win32.js b/benchmark/path/dirname-win32.js
index 551956efaf..510595d721 100644
--- a/benchmark/path/dirname-win32.js
+++ b/benchmark/path/dirname-win32.js
@@ -12,13 +12,13 @@ const bench = common.createBenchmark(main, {
'foo\\bar',
'D:\\foo\\bar\\baz\\asdf\\quux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32.dirname(path);
+ win32.dirname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/extname-posix.js b/benchmark/path/extname-posix.js
index 1c7d9e9449..ee1ea07eeb 100644
--- a/benchmark/path/extname-posix.js
+++ b/benchmark/path/extname-posix.js
@@ -15,13 +15,13 @@ const bench = common.createBenchmark(main, {
'/foo/bar/baz/asdf/quux',
'/foo/bar/baz/asdf/quux.foobarbazasdfquux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- posix.extname(path);
+ posix.extname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/extname-win32.js b/benchmark/path/extname-win32.js
index 4378f8119a..1de4bca28a 100644
--- a/benchmark/path/extname-win32.js
+++ b/benchmark/path/extname-win32.js
@@ -15,13 +15,13 @@ const bench = common.createBenchmark(main, {
'D:\\foo\\bar\\baz\\asdf\\quux',
'\\foo\\bar\\baz\\asdf\\quux.foobarbazasdfquux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32.extname(path);
+ win32.extname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/format-posix.js b/benchmark/path/format-posix.js
index bae1ae1e23..9c555f232c 100644
--- a/benchmark/path/format-posix.js
+++ b/benchmark/path/format-posix.js
@@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
props: [
['/', '/home/user/dir', 'index.html', '.html', 'index'].join('|'),
],
- n: [1e7]
+ n: [1e6]
});
function main({ n, props }) {
@@ -14,13 +14,15 @@ function main({ n, props }) {
const obj = {
root: props[0] || '',
dir: props[1] || '',
- base: props[2] || '',
+ base: '',
ext: props[3] || '',
- name: props[4] || '',
+ name: '',
};
bench.start();
for (var i = 0; i < n; i++) {
+ obj.base = `a${i}${props[2] || ''}`;
+ obj.name = `a${i}${props[4] || ''}`;
posix.format(obj);
}
bench.end(n);
diff --git a/benchmark/path/format-win32.js b/benchmark/path/format-win32.js
index efb3fcd2c8..65315c4dd6 100644
--- a/benchmark/path/format-win32.js
+++ b/benchmark/path/format-win32.js
@@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
props: [
['C:\\', 'C:\\path\\dir', 'index.html', '.html', 'index'].join('|'),
],
- n: [1e7]
+ n: [1e6]
});
function main({ n, props }) {
@@ -14,13 +14,15 @@ function main({ n, props }) {
const obj = {
root: props[0] || '',
dir: props[1] || '',
- base: props[2] || '',
+ base: '',
ext: props[3] || '',
- name: props[4] || '',
+ name: '',
};
bench.start();
for (var i = 0; i < n; i++) {
+ obj.base = `a${i}${props[2] || ''}`;
+ obj.name = `a${i}${props[4] || ''}`;
win32.format(obj);
}
bench.end(n);
diff --git a/benchmark/path/isAbsolute-posix.js b/benchmark/path/isAbsolute-posix.js
index 96da0e01c6..dd0dfd1964 100644
--- a/benchmark/path/isAbsolute-posix.js
+++ b/benchmark/path/isAbsolute-posix.js
@@ -10,13 +10,13 @@ const bench = common.createBenchmark(main, {
'/baz/..',
'bar/baz',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- posix.isAbsolute(path);
+ posix.isAbsolute(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/isAbsolute-win32.js b/benchmark/path/isAbsolute-win32.js
index edb84e8077..ff03f2628a 100644
--- a/benchmark/path/isAbsolute-win32.js
+++ b/benchmark/path/isAbsolute-win32.js
@@ -11,13 +11,13 @@ const bench = common.createBenchmark(main, {
'C:baz\\..',
'bar\\baz',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32.isAbsolute(path);
+ win32.isAbsolute(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/join-posix.js b/benchmark/path/join-posix.js
index 2ba1a4299f..e573166d7a 100644
--- a/benchmark/path/join-posix.js
+++ b/benchmark/path/join-posix.js
@@ -6,15 +6,22 @@ const bench = common.createBenchmark(main, {
paths: [
['/foo', 'bar', '', 'baz/asdf', 'quux', '..'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
const args = paths.split('|');
+ const copy = [...args];
+ const orig = copy[1];
bench.start();
for (var i = 0; i < n; i++) {
- posix.join.apply(null, args);
+ if (i % 3 === 0) {
+ copy[1] = `${orig}${i}`;
+ posix.join(...copy);
+ } else {
+ posix.join(...args);
+ }
}
bench.end(n);
}
diff --git a/benchmark/path/join-win32.js b/benchmark/path/join-win32.js
index 42449542aa..cd69836c00 100644
--- a/benchmark/path/join-win32.js
+++ b/benchmark/path/join-win32.js
@@ -6,15 +6,22 @@ const bench = common.createBenchmark(main, {
paths: [
['C:\\foo', 'bar', '', 'baz\\asdf', 'quux', '..'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
const args = paths.split('|');
+ const copy = [...args];
+ const orig = copy[1];
bench.start();
for (var i = 0; i < n; i++) {
- win32.join.apply(null, args);
+ if (i % 3 === 0) {
+ copy[1] = `${orig}${i}`;
+ win32.join(...copy);
+ } else {
+ win32.join(...args);
+ }
}
bench.end(n);
}
diff --git a/benchmark/path/makeLong-win32.js b/benchmark/path/makeLong-win32.js
index f300f47cf5..45d0d8de60 100644
--- a/benchmark/path/makeLong-win32.js
+++ b/benchmark/path/makeLong-win32.js
@@ -9,13 +9,13 @@ const bench = common.createBenchmark(main, {
'\\\\foo\\bar',
'\\\\?\\foo',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32._makeLong(path);
+ win32._makeLong(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/normalize-posix.js b/benchmark/path/normalize-posix.js
index 7b5c2b1cf9..4383cff4a5 100644
--- a/benchmark/path/normalize-posix.js
+++ b/benchmark/path/normalize-posix.js
@@ -11,13 +11,13 @@ const bench = common.createBenchmark(main, {
'/foo/bar',
'/foo/bar//baz/asdf/quux/..',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- posix.normalize(path);
+ posix.normalize(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/normalize-win32.js b/benchmark/path/normalize-win32.js
index 749523daa8..319c391d17 100644
--- a/benchmark/path/normalize-win32.js
+++ b/benchmark/path/normalize-win32.js
@@ -11,13 +11,13 @@ const bench = common.createBenchmark(main, {
'C:\\foo\\bar',
'C:\\foo\\bar\\\\baz\\asdf\\quux\\..',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
- win32.normalize(path);
+ win32.normalize(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/parse-posix.js b/benchmark/path/parse-posix.js
index 00fdc6a3ad..7fb1d55099 100644
--- a/benchmark/path/parse-posix.js
+++ b/benchmark/path/parse-posix.js
@@ -12,16 +12,13 @@ const bench = common.createBenchmark(main, {
'foo/bar',
'/foo/bar/baz/asdf/.quux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
- for (var i = 0; i < n; i++) {
- posix.parse(path);
- }
bench.start();
- for (i = 0; i < n; i++) {
- posix.parse(path);
+ for (let i = 0; i < n; i++) {
+ posix.parse(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/parse-win32.js b/benchmark/path/parse-win32.js
index 5bcc150d1b..ea4bc34a84 100644
--- a/benchmark/path/parse-win32.js
+++ b/benchmark/path/parse-win32.js
@@ -13,16 +13,13 @@ const bench = common.createBenchmark(main, {
'foo\\bar',
'\\foo\\bar\\baz\\asdf\\.quux',
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, path }) {
- for (var i = 0; i < n; i++) {
- win32.parse(path);
- }
bench.start();
- for (i = 0; i < n; i++) {
- win32.parse(path);
+ for (let i = 0; i < n; i++) {
+ win32.parse(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
}
diff --git a/benchmark/path/relative-posix.js b/benchmark/path/relative-posix.js
index caf1996135..2c4dd31d27 100644
--- a/benchmark/path/relative-posix.js
+++ b/benchmark/path/relative-posix.js
@@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
['/foo/bar/baz/quux', '/foo/bar/baz/quux'].join('|'),
['/foo/bar/baz/quux', '/var/log'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
@@ -22,13 +22,13 @@ function main({ n, paths }) {
to = paths.slice(delimIdx + 1);
paths = paths.slice(0, delimIdx);
}
- for (var i = 0; i < n; i++) {
- posix.relative(paths, to);
- }
bench.start();
- for (i = 0; i < n; i++) {
- posix.relative(paths, to);
+ for (let i = 0; i < n; i++) {
+ if (i % 3 === 0)
+ posix.relative(`${paths}${i}`, `${to}${i}`);
+ else
+ posix.relative(paths, to);
}
bench.end(n);
}
diff --git a/benchmark/path/relative-win32.js b/benchmark/path/relative-win32.js
index 81fd10b46c..5f34fdf8fd 100644
--- a/benchmark/path/relative-win32.js
+++ b/benchmark/path/relative-win32.js
@@ -10,7 +10,7 @@ const bench = common.createBenchmark(main, {
['C:\\foo\\BAR\\BAZ', 'C:\\foo\\bar\\baz'].join('|'),
['C:\\foo\\bar\\baz\\quux', 'C:\\'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
@@ -21,14 +21,12 @@ function main({ n, paths }) {
paths = paths.slice(0, delimIdx);
}
- // Warmup
- for (var i = 0; i < n; i++) {
- win32.relative(paths, to);
- }
-
bench.start();
- for (i = 0; i < n; i++) {
- win32.relative(paths, to);
+ for (let i = 0; i < n; i++) {
+ if (i % 3 === 0)
+ win32.relative(`${paths}${i}`, `${to}${i}`);
+ else
+ win32.relative(paths, to);
}
bench.end(n);
}
diff --git a/benchmark/path/resolve-posix.js b/benchmark/path/resolve-posix.js
index 14b7fd1096..3cdf1cd49a 100644
--- a/benchmark/path/resolve-posix.js
+++ b/benchmark/path/resolve-posix.js
@@ -9,15 +9,22 @@ const bench = common.createBenchmark(main, {
['foo/bar', '/tmp/file/', '..', 'a/../subfile'].join('|'),
['a/b/c/', '../../..'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
const args = paths.split('|');
+ const copy = [...args];
+ const orig = copy[0];
bench.start();
for (var i = 0; i < n; i++) {
- posix.resolve.apply(null, args);
+ if (i % 3 === 0) {
+ copy[0] = `${orig}${i}`;
+ posix.resolve(...copy);
+ } else {
+ posix.resolve(...args);
+ }
}
bench.end(n);
}
diff --git a/benchmark/path/resolve-win32.js b/benchmark/path/resolve-win32.js
index 83e10042b4..cf8144ef2c 100644
--- a/benchmark/path/resolve-win32.js
+++ b/benchmark/path/resolve-win32.js
@@ -9,15 +9,22 @@ const bench = common.createBenchmark(main, {
['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'].join('|'),
['c:/blah\\blah', 'd:/games', 'c:../a'].join('|'),
],
- n: [1e6]
+ n: [1e5]
});
function main({ n, paths }) {
const args = paths.split('|');
+ const copy = [...args];
+ const orig = copy[0];
bench.start();
for (var i = 0; i < n; i++) {
- win32.resolve.apply(null, args);
+ if (i % 3 === 0) {
+ copy[0] = `${orig}${i}`;
+ win32.resolve(...copy);
+ } else {
+ win32.resolve(...args);
+ }
}
bench.end(n);
}