benchmark: (path) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
32b3cad576
commit
92953fa194
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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] || '',
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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] || '',
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -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.normalize(input);
|
||||
win32.normalize(path);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -15,17 +15,13 @@ 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 }) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
posix.parse(path);
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
posix.parse(path);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -16,17 +16,13 @@ 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 }) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
win32.parse(path);
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
win32.parse(path);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -15,23 +15,20 @@ const bench = common.createBenchmark(main, {
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
const n = +conf.n;
|
||||
const p = path.posix;
|
||||
var from = String(conf.paths);
|
||||
function main({ n, paths }) {
|
||||
var to = '';
|
||||
const delimIdx = from.indexOf('|');
|
||||
const delimIdx = paths.indexOf('|');
|
||||
if (delimIdx > -1) {
|
||||
to = from.slice(delimIdx + 1);
|
||||
from = from.slice(0, delimIdx);
|
||||
to = paths.slice(delimIdx + 1);
|
||||
paths = paths.slice(0, delimIdx);
|
||||
}
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.relative(from, to);
|
||||
posix.relative(paths, to);
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (i = 0; i < n; i++) {
|
||||
p.relative(from, to);
|
||||
posix.relative(paths, to);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -13,25 +13,22 @@ const bench = common.createBenchmark(main, {
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
function main(conf) {
|
||||
const n = +conf.n;
|
||||
const p = path.win32;
|
||||
var from = String(conf.paths);
|
||||
function main({ n, paths }) {
|
||||
var to = '';
|
||||
const delimIdx = from.indexOf('|');
|
||||
const delimIdx = paths.indexOf('|');
|
||||
if (delimIdx > -1) {
|
||||
to = from.slice(delimIdx + 1);
|
||||
from = from.slice(0, delimIdx);
|
||||
to = paths.slice(delimIdx + 1);
|
||||
paths = paths.slice(0, delimIdx);
|
||||
}
|
||||
|
||||
// Warmup
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.relative(from, to);
|
||||
win32.relative(paths, to);
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (i = 0; i < n; i++) {
|
||||
p.relative(from, to);
|
||||
win32.relative(paths, to);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -12,14 +12,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.resolve.apply(null, args);
|
||||
posix.resolve.apply(null, args);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -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: [
|
||||
@ -12,14 +12,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.resolve.apply(null, args);
|
||||
win32.resolve.apply(null, args);
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user