Skip to content

Instantly share code, notes, and snippets.

@Hypercubed
Created June 11, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hypercubed/97a249f84f8273a3a4d03ad68de2749d to your computer and use it in GitHub Desktop.
Save Hypercubed/97a249f84f8273a3a4d03ad68de2749d to your computer and use it in GitHub Desktop.
globby - chuhai
'use strict';
var fs = require('fs');
var test = require('ava');
var rimraf = require('rimraf');
var globbyMaster = require('globby');
var gs = require('glob-stream');
var suite = require('chuhai');
var globby = require('./');
var BENCH_DIR = 'bench';
var benchs = [{
name: 'negative globs (some files inside dir)',
patterns: ['a/*', '!a/c*']
}, {
name: 'negative globs (whole dir)',
patterns: ['a/*', '!a/**']
}, {
name: 'multiple positive globs',
patterns: ['a/*', 'b/*']
}];
test.before(function before() {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
fs.mkdirSync(BENCH_DIR);
process.chdir(BENCH_DIR);
['a', 'b'].forEach(function (dir) {
var path = dir + '/';
fs.mkdirSync(path);
for (var i = 0; i < 500; i++) {
fs.writeFileSync(path + (i < 100 ? 'c' : 'd') + i, '');
}
});
});
benchs.forEach(benchmark => {
test(benchmark.name, t => {
return suite(benchmark.name, function (s) {
s.set('maxTime', 0.01);
s.set('minSamples', 10);
s.set('async', false);
s.cycle(function (e) {
t.falsy(e.target.error, e.target.name + ' runs without error');
});
s.bench('globby async (working directory)', deferred => {
globby(benchmark.patterns)
.then(deferred.resolve.bind(deferred, null), deferred.resolve);
}, {defer: true});
s.bench('globby async (upstream/master)', deferred => {
globbyMaster(benchmark.patterns)
.then(deferred.resolve.bind(deferred, null), deferred.resolve);
}, {defer: true});
s.bench('globby sync (working directory)', () => {
globby.sync(benchmark.patterns);
});
s.bench('globby sync (upstream/master)', () => {
globbyMaster.sync(benchmark.patterns);
});
s.bench('glob-stream', deferred => {
gs.create(benchmark.patterns)
.on('data', () => {})
.on('end', deferred.resolve.bind(deferred, null));
}, {defer: true});
});
});
});
test.after(function after() {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
});

negative globs (some files inside dir)

globby sync (working directory) x 208 ops/sec ±5.99% (10 runs sampled)
globby sync (upstream/master) x 199 ops/sec ±10.89% (10 runs sampled)
globby async (upstream/master) x 118 ops/sec ±5.34% (10 runs sampled)
glob-stream x 105 ops/sec ±5.77% (10 runs sampled)
globby async (working directory) x 110 ops/sec ±13.59% (10 runs sampled)

Fastest is globby sync (working directory), globby sync (upstream/master)

negative globs (whole dir)

globby sync (working directory) x 16,912 ops/sec ±5.40% (10 runs sampled)
globby sync (upstream/master) x 16,630 ops/sec ±10.45% (10 runs sampled)
globby async (upstream/master) x 10,446 ops/sec ±3.80% (10 runs sampled)
globby async (working directory) x 10,432 ops/sec ±4.85% (10 runs sampled)
glob-stream x 72.75 ops/sec ±24.62% (10 runs sampled)

Fastest is globby sync (working directory), globby sync (upstream/master)

multiple positive globs

globby sync (working directory) x 109 ops/sec ±5.81% (10 runs sampled)
globby sync (upstream/master) x 103 ops/sec ±4.70% (10 runs sampled)
globby async (upstream/master) x 52.77 ops/sec ±2.90% (10 runs sampled)
globby async (working directory) x 50.69 ops/sec ±9.38% (10 runs sampled)
glob-stream x 37.81 ops/sec ±28.62% (10 runs sampled)

Fastest is globby sync (working directory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment