Skip to content

Instantly share code, notes, and snippets.

@pvdlg
Created January 30, 2018 20:12
Show Gist options
  • Save pvdlg/8f72824d81263efc71b30fd443aa8b0e to your computer and use it in GitHub Desktop.
Save pvdlg/8f72824d81263efc71b30fd443aa8b0e to your computer and use it in GitHub Desktop.
'use strict';
/* global after, before, bench, suite */
const fs = require('fs');
const rimraf = require('rimraf');
const fastGlob = require('fast-glob');
const glob = require('glob');
const BENCH_DIR = 'bench';
const runners = [{
name: 'fast-glob sync',
run: (patterns, ignore) => {
fastGlob.sync(patterns, {ignore});
}
}, {
name: 'glob sync',
run: (patterns, ignore) => {
glob.sync(patterns, {ignore});
}
}];
const benchs = [{
name: 'negative globs (whole dir)',
patterns: 'a/*',
ignore: ['a']
},
{
name: 'negative globs (whole dir with /**)',
patterns: 'a/*',
ignore: ['a/**']
}];
before(() => {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
fs.mkdirSync(BENCH_DIR);
process.chdir(BENCH_DIR);
['a', 'b']
.map(dir => `${dir}/`)
.forEach(dir => {
fs.mkdirSync(dir);
for (let i = 0; i < 500; i++) {
fs.writeFileSync(dir + (i < 100 ? 'c' : 'd') + i, '');
}
});
});
after(() => {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
});
benchs.forEach(benchmark => {
suite(benchmark.name, () => {
runners.forEach(runner => bench(runner.name, runner.run.bind(null, benchmark.patterns, benchmark.ignore)));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment