Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '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)));
- });
- });
Add Comment
Please, Sign In to add comment