Created
November 8, 2016 23:28
-
-
Save shennan/f93af25bf032981c714d17d37a7462b1 to your computer and use it in GitHub Desktop.
A benchmark for async/sync node-fs-extra passStats option
This file contains hidden or 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
var Benchmark = require('benchmark'); | |
var fse = require('fs-extra'); // this is an npm link to local version of node-fs-extra | |
var path = require('path'); | |
var async = require('async'); | |
var suites = { | |
'Asynchronous': new Benchmark.Suite, | |
'Synchronous': new Benchmark.Suite | |
} | |
// declare input/output paths | |
var inputPath = path.join('dummy', 'input'); | |
var outputPath = path.join('dummy', 'output') | |
// remove output path if it exists | |
fse.removeSync(outputPath); | |
// iterate suites | |
async.eachOfSeries(suites, function (suite, name, suiteFinished) { | |
var asynchronous = name == 'Asynchronous'; | |
var filter = function () { return true; }; | |
var copyfunc = asynchronous ? fse.copy : fse.copySync; | |
console.log(name); | |
suite | |
.add('WithFilter', function (deffered) { | |
copyfunc(inputPath, path.join(outputPath, name + this.name), { | |
filter: filter, | |
passStats: false | |
}, | |
function () { | |
if (deffered && deffered.resolve) | |
deffered.resolve(); | |
} | |
); | |
}, {defer: asynchronous}) | |
.add('WithFilterAndStats', function (deffered) { | |
copyfunc(inputPath, path.join(outputPath, name + this.name), { | |
filter: filter, | |
passStats: true | |
}, | |
function () { | |
if (deffered && deffered.resolve) | |
deffered.resolve(); | |
} | |
); | |
}, {defer: asynchronous}) | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
suiteFinished(null); | |
}) | |
.run({ 'async': asynchronous }); | |
}, function () { | |
console.log('done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment