Skip to content

Commit

Permalink
benchmark: (path) use destructuring
Browse files Browse the repository at this point in the history
PR-URL: nodejs#18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MayaLekova committed May 8, 2018
1 parent 0a0cecc commit 05b591e
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 153 deletions.
15 changes: 6 additions & 9 deletions benchmark/path/basename-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
pathext: [
Expand All @@ -18,20 +18,17 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

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

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

const bench = common.createBenchmark(main, {
pathext: [
Expand All @@ -18,20 +18,17 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

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

bench.start();
for (var i = 0; i < n; i++) {
p.basename(input, ext);
posix.basename(pathext, ext);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/dirname-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -15,14 +15,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.dirname(input);
posix.dirname(path);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/dirname-win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { win32 } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -15,14 +15,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.dirname(input);
win32.dirname(path);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/extname-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -18,14 +18,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.extname(input);
posix.extname(path);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/extname-win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { win32 } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -18,14 +18,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.extname(input);
win32.extname(path);
}
bench.end(n);
}
10 changes: 4 additions & 6 deletions benchmark/path/format-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
props: [
Expand All @@ -9,10 +9,8 @@ const bench = common.createBenchmark(main, {
n: [1e7]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const props = String(conf.props).split('|');
function main({ n, props }) {
props = props.split('|');
const obj = {
root: props[0] || '',
dir: props[1] || '',
Expand All @@ -23,7 +21,7 @@ function main(conf) {

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

const bench = common.createBenchmark(main, {
props: [
Expand All @@ -9,10 +9,8 @@ const bench = common.createBenchmark(main, {
n: [1e7]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const props = String(conf.props).split('|');
function main({ n, props }) {
props = props.split('|');
const obj = {
root: props[0] || '',
dir: props[1] || '',
Expand All @@ -23,7 +21,7 @@ function main(conf) {

bench.start();
for (var i = 0; i < n; i++) {
p.format(obj);
win32.format(obj);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/isAbsolute-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -13,14 +13,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.isAbsolute(input);
posix.isAbsolute(path);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/isAbsolute-win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { win32 } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -14,14 +14,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.isAbsolute(input);
win32.isAbsolute(path);
}
bench.end(n);
}
10 changes: 4 additions & 6 deletions benchmark/path/join-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
paths: [
Expand All @@ -9,14 +9,12 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const args = String(conf.paths).split('|');
function main({ n, paths }) {
const args = paths.split('|');

bench.start();
for (var i = 0; i < n; i++) {
p.join.apply(null, args);
posix.join.apply(null, args);
}
bench.end(n);
}
10 changes: 4 additions & 6 deletions benchmark/path/join-win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { win32 } = require('path');

const bench = common.createBenchmark(main, {
paths: [
Expand All @@ -9,14 +9,12 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const args = String(conf.paths).split('|');
function main({ n, paths }) {
const args = paths.split('|');

bench.start();
for (var i = 0; i < n; i++) {
p.join.apply(null, args);
win32.join.apply(null, args);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/makeLong-win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { win32 } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -12,14 +12,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.win32;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p._makeLong(input);
win32._makeLong(path);
}
bench.end(n);
}
10 changes: 3 additions & 7 deletions benchmark/path/normalize-posix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common.js');
const path = require('path');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
path: [
Expand All @@ -14,14 +14,10 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});

function main(conf) {
const n = +conf.n;
const p = path.posix;
const input = String(conf.path);

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
p.normalize(input);
posix.normalize(path);
}
bench.end(n);
}
Loading

0 comments on commit 05b591e

Please sign in to comment.