Skip to content

Commit 0d15161

Browse files
nwoltmansilverwind
authored andcommitted
benchmark: Add some path benchmarks for #1778
Path functions being benchmarked are: * format * isAbsolute * join * normalize * relative * resolve PR-URL: #1778 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent bca53dc commit 0d15161

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

benchmark/path/format.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e7],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var p = path[conf.type];
12+
var test = conf.type === 'win32' ? {
13+
root: 'C:\\',
14+
dir: 'C:\\path\\dir',
15+
base: 'index.html',
16+
ext: '.html',
17+
name: 'index'
18+
} : {
19+
root : '/',
20+
dir : '/home/user/dir',
21+
base : 'index.html',
22+
ext : '.html',
23+
name : 'index'
24+
};
25+
26+
bench.start();
27+
for (var i = 0; i < n; i++) {
28+
p.format(test);
29+
}
30+
bench.end(n);
31+
}

benchmark/path/isAbsolute.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e6],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var p = path[conf.type];
12+
var tests = conf.type === 'win32'
13+
? ['//server', 'C:\\baz\\..', 'bar\\baz', '.']
14+
: ['/foo/bar', '/baz/..', 'bar/baz', '.'];
15+
16+
bench.start();
17+
for (var i = 0; i < n; i++) {
18+
runTests(p, tests);
19+
}
20+
bench.end(n);
21+
}
22+
23+
function runTests(p, tests) {
24+
for (var i = 0; i < tests.length; i++) {
25+
p.isAbsolute(tests[i]);
26+
}
27+
}

benchmark/path/join.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e6],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var p = path[conf.type];
12+
13+
bench.start();
14+
for (var i = 0; i < n; i++) {
15+
p.join('/foo', 'bar', '', 'baz/asdf', 'quux', '..');
16+
}
17+
bench.end(n);
18+
}

benchmark/path/normalize.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e6],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var p = path[conf.type];
12+
13+
bench.start();
14+
for (var i = 0; i < n; i++) {
15+
p.normalize('/foo/bar//baz/asdf/quux/..');
16+
}
17+
bench.end(n);
18+
}

benchmark/path/relative.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e5],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var runTest = conf.type === 'win32' ? runWin32Test : runPosixTest;
12+
13+
bench.start();
14+
for (var i = 0; i < n; i++) {
15+
runTest();
16+
}
17+
bench.end(n);
18+
}
19+
20+
function runWin32Test() {
21+
path.win32.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb');
22+
}
23+
24+
function runPosixTest() {
25+
path.posix.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
26+
}

benchmark/path/resolve.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var common = require('../common.js');
2+
var path = require('path');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: ['win32', 'posix'],
6+
n: [1e6],
7+
});
8+
9+
function main(conf) {
10+
var n = +conf.n;
11+
var p = path[conf.type];
12+
13+
bench.start();
14+
for (var i = 0; i < n; i++) {
15+
p.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile');
16+
}
17+
bench.end(n);
18+
}

0 commit comments

Comments
 (0)