Skip to content

Commit

Permalink
benchmark: split path benchmarks
Browse files Browse the repository at this point in the history
This commit splits each path benchmark into separate posix and
Windows benchmark files. This allows benchmarking (platform-)specific
inputs against specific platforms (only).

PR-URL: #5123
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex authored and rvagg committed Feb 10, 2016
1 parent 8d713d8 commit edf8f8a
Show file tree
Hide file tree
Showing 24 changed files with 592 additions and 152 deletions.
43 changes: 43 additions & 0 deletions benchmark/path/basename-posix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
pathext: [
'',
'/',
'/foo',
'/foo/.bar.baz',
['/foo/.bar.baz', '.baz'].join('|'),
'foo',
'foo/bar.',
['foo/bar.', '.'].join('|'),
'/foo/bar/baz/asdf/quux.html',
['/foo/bar/baz/asdf/quux.html', '.html'].join('|')
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path.posix;
var input = '' + conf.pathext;
var ext;
var extIdx = input.indexOf('|');
if (extIdx !== -1) {
ext = input.slice(extIdx + 1);
input = input.slice(0, extIdx);
}

// Force optimization before starting the benchmark
p.basename(input, ext);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.basename)');
p.basename(input, ext);

bench.start();
for (var i = 0; i < n; i++) {
p.basename(input, ext);
}
bench.end(n);
}
43 changes: 43 additions & 0 deletions benchmark/path/basename-win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
pathext: [
'',
'C:\\',
'C:\\foo',
'D:\\foo\\.bar.baz',
['E:\\foo\\.bar.baz','.baz'].join('|'),
'foo',
'foo\\bar.',
['foo\\bar.', '.'].join('|'),
'\\foo\\bar\\baz\\asdf\\quux.html',
['\\foo\\bar\\baz\\asdf\\quux.html', '.html'].join('|')
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path.win32;
var input = '' + conf.pathext;
var ext;
var extIdx = input.indexOf('|');
if (extIdx !== -1) {
ext = input.slice(extIdx + 1);
input = input.slice(0, extIdx);
}

// Force optimization before starting the benchmark
p.basename(input, ext);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.basename)');
p.basename(input, ext);

bench.start();
for (var i = 0; i < n; i++) {
p.basename(input, ext);
}
bench.end(n);
}
26 changes: 0 additions & 26 deletions benchmark/path/basename.js

This file was deleted.

21 changes: 15 additions & 6 deletions benchmark/path/dirname.js → benchmark/path/dirname-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
type: ['win32', 'posix'],
n: [1e6],
path: [
'',
'/',
'/foo',
'/foo/bar',
'foo',
'foo/bar',
'/foo/bar/baz/asdf/quux'
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path[conf.type];
var p = path.posix;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.dirname('/foo/bar/baz/asdf/quux');
p.dirname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.dirname)');
p.dirname('/foo/bar/baz/asdf/quux');
p.dirname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.dirname('/foo/bar/baz/asdf/quux');
p.dirname(input);
}
bench.end(n);
}
34 changes: 34 additions & 0 deletions benchmark/path/dirname-win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
'',
'\\',
'\\foo',
'C:\\foo\\bar',
'foo',
'foo\\bar',
'D:\\foo\\bar\\baz\\asdf\\quux'
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path.win32;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.dirname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.dirname)');
p.dirname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.dirname(input);
}
bench.end(n);
}
37 changes: 37 additions & 0 deletions benchmark/path/extname-posix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
'',
'/',
'/foo',
'foo/.bar.baz',
'index.html',
'index',
'foo/bar/..baz.quux',
'foo/bar/...baz.quux',
'/foo/bar/baz/asdf/quux',
'/foo/bar/baz/asdf/quux.foobarbazasdfquux'
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path.posix;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.extname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.extname)');
p.extname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.extname(input);
}
bench.end(n);
}
37 changes: 37 additions & 0 deletions benchmark/path/extname-win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
path: [
'',
'\\',
'C:\\foo',
'foo\\.bar.baz',
'index.html',
'index',
'foo\\bar\\..baz.quux',
'foo\\bar\\...baz.quux',
'D:\\foo\\bar\\baz\\asdf\\quux',
'\\foo\\bar\\baz\\asdf\\quux.foobarbazasdfquux'
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path.win32;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.extname(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.extname)');
p.extname(input);

bench.start();
for (var i = 0; i < n; i++) {
p.extname(input);
}
bench.end(n);
}
33 changes: 15 additions & 18 deletions benchmark/path/format.js → benchmark/path/format-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,33 @@ var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
type: ['win32', 'posix'],
n: [1e7],
props: [
['/', '/home/user/dir', 'index.html', '.html', 'index'].join('|')
],
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'
var p = path.posix;
var props = ('' + conf.props).split('|');
var obj = {
root: props[0] || '',
dir: props[1] || '',
base: props[2] || '',
ext: props[3] || '',
name: props[4] || '',
};

// Force optimization before starting the benchmark
p.format(test);
p.format(obj);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.format)');
p.format(test);
p.format(obj);

bench.start();
for (var i = 0; i < n; i++) {
p.format(test);
p.format(obj);
}
bench.end(n);
}
35 changes: 35 additions & 0 deletions benchmark/path/format-win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var common = require('../common.js');
var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
props: [
['C:\\', 'C:\\path\\dir', 'index.html', '.html', 'index'].join('|')
],
n: [1e7]
});

function main(conf) {
var n = +conf.n;
var p = path.win32;
var props = ('' + conf.props).split('|');
var obj = {
root: props[0] || '',
dir: props[1] || '',
base: props[2] || '',
ext: props[3] || '',
name: props[4] || '',
};

// Force optimization before starting the benchmark
p.format(obj);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.format)');
p.format(obj);

bench.start();
for (var i = 0; i < n; i++) {
p.format(obj);
}
bench.end(n);
}
22 changes: 14 additions & 8 deletions benchmark/path/extname.js → benchmark/path/isAbsolute-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@ var path = require('path');
var v8 = require('v8');

var bench = common.createBenchmark(main, {
type: ['win32', 'posix'],
n: [1e6],
path: [
'',
'.',
'/foo/bar',
'/baz/..',
'bar/baz'
],
n: [1e6]
});

function main(conf) {
var n = +conf.n;
var p = path[conf.type];
var p = path.posix;
var input = '' + conf.path;

// Force optimization before starting the benchmark
p.extname('index.html');
p.isAbsolute(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(p.extname)');
p.extname('index.html');
eval('%OptimizeFunctionOnNextCall(p.isAbsolute)');
p.isAbsolute(input);

bench.start();
for (var i = 0; i < n; i++) {
p.extname('index.html');
p.extname('index');
p.isAbsolute(input);
}
bench.end(n);
}
Loading

0 comments on commit edf8f8a

Please sign in to comment.