summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorNathan Woltman <nwoltman@outlook.com>2015-06-05 20:43:48 -0400
committerRoman Reiss <me@silverwind.io>2015-07-04 13:30:20 +0200
commit0d15161c2402be7bcdb575bc425307d8c9fef32b (patch)
treebc0d1549018e7d2b0f65c387c7b56c92fc3fd2eb /benchmark
parentbca53dce76f98aba9bcc3b4cc2ba0f004bfc6aae (diff)
downloadandroid-node-v8-0d15161c2402be7bcdb575bc425307d8c9fef32b.tar.gz
android-node-v8-0d15161c2402be7bcdb575bc425307d8c9fef32b.tar.bz2
android-node-v8-0d15161c2402be7bcdb575bc425307d8c9fef32b.zip
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>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/path/format.js31
-rw-r--r--benchmark/path/isAbsolute.js27
-rw-r--r--benchmark/path/join.js18
-rw-r--r--benchmark/path/normalize.js18
-rw-r--r--benchmark/path/relative.js26
-rw-r--r--benchmark/path/resolve.js18
6 files changed, 138 insertions, 0 deletions
diff --git a/benchmark/path/format.js b/benchmark/path/format.js
new file mode 100644
index 0000000000..02fb691fe7
--- /dev/null
+++ b/benchmark/path/format.js
@@ -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);
+}
diff --git a/benchmark/path/isAbsolute.js b/benchmark/path/isAbsolute.js
new file mode 100644
index 0000000000..c9489fe85c
--- /dev/null
+++ b/benchmark/path/isAbsolute.js
@@ -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]);
+ }
+}
diff --git a/benchmark/path/join.js b/benchmark/path/join.js
new file mode 100644
index 0000000000..54d02a6450
--- /dev/null
+++ b/benchmark/path/join.js
@@ -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);
+}
diff --git a/benchmark/path/normalize.js b/benchmark/path/normalize.js
new file mode 100644
index 0000000000..10ca23037a
--- /dev/null
+++ b/benchmark/path/normalize.js
@@ -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);
+}
diff --git a/benchmark/path/relative.js b/benchmark/path/relative.js
new file mode 100644
index 0000000000..3e12f8b532
--- /dev/null
+++ b/benchmark/path/relative.js
@@ -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');
+}
diff --git a/benchmark/path/resolve.js b/benchmark/path/resolve.js
new file mode 100644
index 0000000000..ecf30f32fa
--- /dev/null
+++ b/benchmark/path/resolve.js
@@ -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);
+}