Created
May 19, 2019 08:51
-
-
Save endiliey/9b0879291d3b9941a35e25b1fe47be5a to your computer and use it in GitHub Desktop.
benchmark path.basename(file, path.extname(file)) vs path.parse(file).name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const Benchmark = require('benchmark'); | |
const suite = new Benchmark.Suite(); | |
const files = [ | |
'C:\\temp\\myfile.html', | |
'a.md', | |
'hello/super.js', | |
'test.ts', | |
'superman/hello/haha.md', | |
]; | |
// add tests | |
suite | |
.add('path parse', function() { | |
files.forEach(file => { | |
path.parse(file).name; | |
}); | |
}) | |
.add('path basename + path extname', function() { | |
files.forEach(file => { | |
path.basename(file, path.extname(file)); | |
}); | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
.run({async: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment