Skip to content

Commit 5b0e3b9

Browse files
BridgeARevanlucas
authored andcommitted
benchmark: (path) use destructuring
PR-URL: #18250 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7bc5bad commit 5b0e3b9

21 files changed

+85
-153
lines changed

benchmark/path/basename-posix.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
pathext: [
@@ -18,20 +18,17 @@ const bench = common.createBenchmark(main, {
1818
n: [1e6]
1919
});
2020

21-
function main(conf) {
22-
const n = +conf.n;
23-
const p = path.posix;
24-
var input = String(conf.pathext);
21+
function main({ n, pathext }) {
2522
var ext;
26-
const extIdx = input.indexOf('|');
23+
const extIdx = pathext.indexOf('|');
2724
if (extIdx !== -1) {
28-
ext = input.slice(extIdx + 1);
29-
input = input.slice(0, extIdx);
25+
ext = pathext.slice(extIdx + 1);
26+
pathext = pathext.slice(0, extIdx);
3027
}
3128

3229
bench.start();
3330
for (var i = 0; i < n; i++) {
34-
p.basename(input, ext);
31+
posix.basename(pathext, ext);
3532
}
3633
bench.end(n);
3734
}

benchmark/path/basename-win32.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
pathext: [
@@ -18,20 +18,17 @@ const bench = common.createBenchmark(main, {
1818
n: [1e6]
1919
});
2020

21-
function main(conf) {
22-
const n = +conf.n;
23-
const p = path.win32;
24-
var input = String(conf.pathext);
21+
function main({ n, pathext }) {
2522
var ext;
26-
const extIdx = input.indexOf('|');
23+
const extIdx = pathext.indexOf('|');
2724
if (extIdx !== -1) {
28-
ext = input.slice(extIdx + 1);
29-
input = input.slice(0, extIdx);
25+
ext = pathext.slice(extIdx + 1);
26+
pathext = pathext.slice(0, extIdx);
3027
}
3128

3229
bench.start();
3330
for (var i = 0; i < n; i++) {
34-
p.basename(input, ext);
31+
posix.basename(pathext, ext);
3532
}
3633
bench.end(n);
3734
}

benchmark/path/dirname-posix.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -15,14 +15,10 @@ const bench = common.createBenchmark(main, {
1515
n: [1e6]
1616
});
1717

18-
function main(conf) {
19-
const n = +conf.n;
20-
const p = path.posix;
21-
const input = String(conf.path);
22-
18+
function main({ n, path }) {
2319
bench.start();
2420
for (var i = 0; i < n; i++) {
25-
p.dirname(input);
21+
posix.dirname(path);
2622
}
2723
bench.end(n);
2824
}

benchmark/path/dirname-win32.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -15,14 +15,10 @@ const bench = common.createBenchmark(main, {
1515
n: [1e6]
1616
});
1717

18-
function main(conf) {
19-
const n = +conf.n;
20-
const p = path.win32;
21-
const input = String(conf.path);
22-
18+
function main({ n, path }) {
2319
bench.start();
2420
for (var i = 0; i < n; i++) {
25-
p.dirname(input);
21+
win32.dirname(path);
2622
}
2723
bench.end(n);
2824
}

benchmark/path/extname-posix.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -18,14 +18,10 @@ const bench = common.createBenchmark(main, {
1818
n: [1e6]
1919
});
2020

21-
function main(conf) {
22-
const n = +conf.n;
23-
const p = path.posix;
24-
const input = String(conf.path);
25-
21+
function main({ n, path }) {
2622
bench.start();
2723
for (var i = 0; i < n; i++) {
28-
p.extname(input);
24+
posix.extname(path);
2925
}
3026
bench.end(n);
3127
}

benchmark/path/extname-win32.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -18,14 +18,10 @@ const bench = common.createBenchmark(main, {
1818
n: [1e6]
1919
});
2020

21-
function main(conf) {
22-
const n = +conf.n;
23-
const p = path.win32;
24-
const input = String(conf.path);
25-
21+
function main({ n, path }) {
2622
bench.start();
2723
for (var i = 0; i < n; i++) {
28-
p.extname(input);
24+
win32.extname(path);
2925
}
3026
bench.end(n);
3127
}

benchmark/path/format-posix.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
props: [
@@ -9,10 +9,8 @@ const bench = common.createBenchmark(main, {
99
n: [1e7]
1010
});
1111

12-
function main(conf) {
13-
const n = +conf.n;
14-
const p = path.posix;
15-
const props = String(conf.props).split('|');
12+
function main({ n, props }) {
13+
props = props.split('|');
1614
const obj = {
1715
root: props[0] || '',
1816
dir: props[1] || '',
@@ -23,7 +21,7 @@ function main(conf) {
2321

2422
bench.start();
2523
for (var i = 0; i < n; i++) {
26-
p.format(obj);
24+
posix.format(obj);
2725
}
2826
bench.end(n);
2927
}

benchmark/path/format-win32.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
props: [
@@ -9,10 +9,8 @@ const bench = common.createBenchmark(main, {
99
n: [1e7]
1010
});
1111

12-
function main(conf) {
13-
const n = +conf.n;
14-
const p = path.win32;
15-
const props = String(conf.props).split('|');
12+
function main({ n, props }) {
13+
props = props.split('|');
1614
const obj = {
1715
root: props[0] || '',
1816
dir: props[1] || '',
@@ -23,7 +21,7 @@ function main(conf) {
2321

2422
bench.start();
2523
for (var i = 0; i < n; i++) {
26-
p.format(obj);
24+
win32.format(obj);
2725
}
2826
bench.end(n);
2927
}

benchmark/path/isAbsolute-posix.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -13,14 +13,10 @@ const bench = common.createBenchmark(main, {
1313
n: [1e6]
1414
});
1515

16-
function main(conf) {
17-
const n = +conf.n;
18-
const p = path.posix;
19-
const input = String(conf.path);
20-
16+
function main({ n, path }) {
2117
bench.start();
2218
for (var i = 0; i < n; i++) {
23-
p.isAbsolute(input);
19+
posix.isAbsolute(path);
2420
}
2521
bench.end(n);
2622
}

benchmark/path/isAbsolute-win32.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -14,14 +14,10 @@ const bench = common.createBenchmark(main, {
1414
n: [1e6]
1515
});
1616

17-
function main(conf) {
18-
const n = +conf.n;
19-
const p = path.win32;
20-
const input = String(conf.path);
21-
17+
function main({ n, path }) {
2218
bench.start();
2319
for (var i = 0; i < n; i++) {
24-
p.isAbsolute(input);
20+
win32.isAbsolute(path);
2521
}
2622
bench.end(n);
2723
}

benchmark/path/join-posix.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
paths: [
@@ -9,14 +9,12 @@ const bench = common.createBenchmark(main, {
99
n: [1e6]
1010
});
1111

12-
function main(conf) {
13-
const n = +conf.n;
14-
const p = path.posix;
15-
const args = String(conf.paths).split('|');
12+
function main({ n, paths }) {
13+
const args = paths.split('|');
1614

1715
bench.start();
1816
for (var i = 0; i < n; i++) {
19-
p.join.apply(null, args);
17+
posix.join.apply(null, args);
2018
}
2119
bench.end(n);
2220
}

benchmark/path/join-win32.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
paths: [
@@ -9,14 +9,12 @@ const bench = common.createBenchmark(main, {
99
n: [1e6]
1010
});
1111

12-
function main(conf) {
13-
const n = +conf.n;
14-
const p = path.win32;
15-
const args = String(conf.paths).split('|');
12+
function main({ n, paths }) {
13+
const args = paths.split('|');
1614

1715
bench.start();
1816
for (var i = 0; i < n; i++) {
19-
p.join.apply(null, args);
17+
win32.join.apply(null, args);
2018
}
2119
bench.end(n);
2220
}

benchmark/path/makeLong-win32.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { win32 } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -12,14 +12,10 @@ const bench = common.createBenchmark(main, {
1212
n: [1e6]
1313
});
1414

15-
function main(conf) {
16-
const n = +conf.n;
17-
const p = path.win32;
18-
const input = String(conf.path);
19-
15+
function main({ n, path }) {
2016
bench.start();
2117
for (var i = 0; i < n; i++) {
22-
p._makeLong(input);
18+
win32._makeLong(path);
2319
}
2420
bench.end(n);
2521
}

benchmark/path/normalize-posix.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const path = require('path');
3+
const { posix } = require('path');
44

55
const bench = common.createBenchmark(main, {
66
path: [
@@ -14,14 +14,10 @@ const bench = common.createBenchmark(main, {
1414
n: [1e6]
1515
});
1616

17-
function main(conf) {
18-
const n = +conf.n;
19-
const p = path.posix;
20-
const input = String(conf.path);
21-
17+
function main({ n, path }) {
2218
bench.start();
2319
for (var i = 0; i < n; i++) {
24-
p.normalize(input);
20+
posix.normalize(path);
2521
}
2622
bench.end(n);
2723
}

0 commit comments

Comments
 (0)