2016-02-20 09:03:16 +08:00
|
|
|
'use strict';
|
2017-09-14 09:48:53 +08:00
|
|
|
const common = require('../common.js');
|
2017-12-30 10:57:01 +08:00
|
|
|
const { posix } = require('path');
|
2015-06-06 08:43:48 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-02-06 11:23:29 +08:00
|
|
|
props: [
|
|
|
|
['/', '/home/user/dir', 'index.html', '.html', 'index'].join('|')
|
|
|
|
],
|
|
|
|
n: [1e7]
|
2015-06-06 08:43:48 +08:00
|
|
|
});
|
|
|
|
|
2017-12-30 10:57:01 +08:00
|
|
|
function main({ n, props }) {
|
|
|
|
props = props.split('|');
|
2017-09-14 09:48:53 +08:00
|
|
|
const obj = {
|
2016-02-06 11:23:29 +08:00
|
|
|
root: props[0] || '',
|
|
|
|
dir: props[1] || '',
|
|
|
|
base: props[2] || '',
|
|
|
|
ext: props[3] || '',
|
|
|
|
name: props[4] || '',
|
2015-06-06 08:43:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; i++) {
|
2017-12-30 10:57:01 +08:00
|
|
|
posix.format(obj);
|
2015-06-06 08:43:48 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|