Guest User

Untitled

a guest
Feb 13th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. 'use strict';
  2. /* global after, before, bench, suite */
  3. const fs = require('fs');
  4. const rimraf = require('rimraf');
  5. const fastGlob = require('fast-glob');
  6. const glob = require('glob');
  7.  
  8. const BENCH_DIR = 'bench';
  9.  
  10. const runners = [{
  11. name: 'fast-glob sync',
  12. run: (patterns, ignore) => {
  13. fastGlob.sync(patterns, {ignore});
  14. }
  15. }, {
  16. name: 'glob sync',
  17. run: (patterns, ignore) => {
  18. glob.sync(patterns, {ignore});
  19. }
  20. }];
  21. const benchs = [{
  22. name: 'negative globs (whole dir)',
  23. patterns: 'a/*',
  24. ignore: ['a']
  25. },
  26. {
  27. name: 'negative globs (whole dir with /**)',
  28. patterns: 'a/*',
  29. ignore: ['a/**']
  30. }];
  31.  
  32. before(() => {
  33. process.chdir(__dirname);
  34. rimraf.sync(BENCH_DIR);
  35. fs.mkdirSync(BENCH_DIR);
  36. process.chdir(BENCH_DIR);
  37. ['a', 'b']
  38. .map(dir => `${dir}/`)
  39. .forEach(dir => {
  40. fs.mkdirSync(dir);
  41. for (let i = 0; i < 500; i++) {
  42. fs.writeFileSync(dir + (i < 100 ? 'c' : 'd') + i, '');
  43. }
  44. });
  45. });
  46.  
  47. after(() => {
  48. process.chdir(__dirname);
  49. rimraf.sync(BENCH_DIR);
  50. });
  51.  
  52. benchs.forEach(benchmark => {
  53. suite(benchmark.name, () => {
  54. runners.forEach(runner => bench(runner.name, runner.run.bind(null, benchmark.patterns, benchmark.ignore)));
  55. });
  56. });
Add Comment
Please, Sign In to add comment