-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
bench.js
73 lines (68 loc) · 1.63 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
/* global after, before, bench, suite */
var fs = require('fs');
var rimraf = require('rimraf');
var globbyMaster = require('globby');
var gs = require('glob-stream');
var globby = require('./');
var BENCH_DIR = 'bench';
var runners = [{
name: 'globby async (working directory)',
run: function (patterns, cb) {
globby(patterns).then(cb.bind(null, null), cb);
}
}, {
name: 'globby async (upstream/master)',
run: function (patterns, cb) {
globbyMaster(patterns).then(cb.bind(null, null), cb);
}
}, {
name: 'globby sync (working directory)',
run: function (patterns) {
globby.sync(patterns);
}
}, {
name: 'globby sync (upstream/master)',
run: function (patterns) {
globbyMaster.sync(patterns);
}
}, {
name: 'glob-stream',
run: function (patterns, cb) {
gs(patterns).on('data', function () {}).on('end', cb);
}
}];
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/*']
}];
before(function () {
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, '');
}
});
});
after(function () {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
});
benchs.forEach(function (benchmark) {
suite(benchmark.name, function () {
runners.forEach(function (runner) {
bench(runner.name, runner.run.bind(null, benchmark.patterns));
});
});
});