Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path: performance and stability improvements on all platforms #5123

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,13 @@ function parseOpts(options) {
var num = keys.length;
var conf = {};
for (var i = 2; i < process.argv.length; i++) {
var match = process.argv[i].match(/^(.+)=(.+)$/);
if (!match || !match[1] || !match[2] || !options[match[1]]) {
var match = process.argv[i].match(/^(.+)=(.*)$/);
if (!match || !match[1] || !options[match[1]]) {
return null;
} else {
conf[match[1]] = isFinite(match[2]) ? +match[2] : match[2]
conf[match[1]] = (match[2].length && isFinite(match[2])
? +match[2]
: match[2]);
num--;
}
}
Expand Down
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);
}
Loading