mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 08:24:38 +00:00
benchmark: Add some path benchmarks for #1778
Path functions being benchmarked are: * format * isAbsolute * join * normalize * relative * resolve PR-URL: https://github.com/nodejs/io.js/pull/1778 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
This commit is contained in:
parent
bca53dce76
commit
0d15161c24
31
benchmark/path/format.js
Normal file
31
benchmark/path/format.js
Normal file
@ -0,0 +1,31 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e7],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path[conf.type];
|
||||
var test = conf.type === 'win32' ? {
|
||||
root: 'C:\\',
|
||||
dir: 'C:\\path\\dir',
|
||||
base: 'index.html',
|
||||
ext: '.html',
|
||||
name: 'index'
|
||||
} : {
|
||||
root : '/',
|
||||
dir : '/home/user/dir',
|
||||
base : 'index.html',
|
||||
ext : '.html',
|
||||
name : 'index'
|
||||
};
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.format(test);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
27
benchmark/path/isAbsolute.js
Normal file
27
benchmark/path/isAbsolute.js
Normal file
@ -0,0 +1,27 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path[conf.type];
|
||||
var tests = conf.type === 'win32'
|
||||
? ['//server', 'C:\\baz\\..', 'bar\\baz', '.']
|
||||
: ['/foo/bar', '/baz/..', 'bar/baz', '.'];
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
runTests(p, tests);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runTests(p, tests) {
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
p.isAbsolute(tests[i]);
|
||||
}
|
||||
}
|
18
benchmark/path/join.js
Normal file
18
benchmark/path/join.js
Normal file
@ -0,0 +1,18 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path[conf.type];
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.join('/foo', 'bar', '', 'baz/asdf', 'quux', '..');
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
18
benchmark/path/normalize.js
Normal file
18
benchmark/path/normalize.js
Normal file
@ -0,0 +1,18 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path[conf.type];
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.normalize('/foo/bar//baz/asdf/quux/..');
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
26
benchmark/path/relative.js
Normal file
26
benchmark/path/relative.js
Normal file
@ -0,0 +1,26 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e5],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var runTest = conf.type === 'win32' ? runWin32Test : runPosixTest;
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
runTest();
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runWin32Test() {
|
||||
path.win32.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb');
|
||||
}
|
||||
|
||||
function runPosixTest() {
|
||||
path.posix.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
|
||||
}
|
18
benchmark/path/resolve.js
Normal file
18
benchmark/path/resolve.js
Normal file
@ -0,0 +1,18 @@
|
||||
var common = require('../common.js');
|
||||
var path = require('path');
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
type: ['win32', 'posix'],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path[conf.type];
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile');
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
Loading…
Reference in New Issue
Block a user