-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.js
91 lines (73 loc) · 2.57 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
const { Suite } = require('benchmark');
const colors = require('ansi-colors');
const argv = require('minimist')(process.argv.slice(2));
const minimatch = require('minimatch');
const braces = require('..');
/**
* Setup
*/
const cycle = (e, newline) => {
process.stdout.write(`\u001b[G ${e.target}${newline ? '\n' : ''}`);
};
const bench = (name, options) => {
const config = { name, ...options };
const suite = new Suite(config);
const add = suite.add.bind(suite);
suite.on('error', console.error);
if (argv.run && !new RegExp(argv.run).test(name)) {
suite.add = () => suite;
return suite;
}
console.log(colors.green(`● ${config.name}`));
suite.add = (key, fn, opts) => {
if (typeof fn !== 'function') opts = fn;
add(key, {
onCycle: e => cycle(e),
onComplete: e => cycle(e, true),
fn,
...opts
});
return suite;
};
return suite;
};
const skip = () => {};
skip.add = () => skip;
skip.run = () => skip;
bench.skip = name => {
console.log(colors.cyan('● ' + colors.unstyle(name) + ' (skipped)'));
return skip;
};
bench('expand - range (expanded)')
.add(' braces', () => braces.expand('foo/{1..250}/bar'))
.add('minimatch', () => minimatch.braceExpand('foo/{1..250}/bar'))
.run();
bench('expand - range (optimized for regex)')
.add(' braces', () => braces.compile('foo/{1..250}/bar'))
.add('minimatch', () => minimatch.makeRe('foo/{1..250}/bar'))
.run();
bench('expand - nested ranges (expanded)')
.add(' braces', () => braces.expand('foo/{a,b,{1..250}}/bar'))
.add('minimatch', () => minimatch.braceExpand('foo/{a,b,{1..250}}/bar'))
.run();
bench('expand - nested ranges (optimized for regex)')
.add(' braces', () => braces.compile('foo/{a,b,{1..250}}/bar'))
.add('minimatch', () => minimatch.makeRe('foo/{a,b,{1..250}}/bar'))
.run();
bench('expand - set (expanded)')
.add(' braces', () => braces.expand('foo/{a,b,c}/bar'))
.add('minimatch', () => minimatch.braceExpand('foo/{a,b,c}/bar'))
.run();
bench('expand - set (optimized for regex)')
.add(' braces', () => braces.compile('foo/{a,b,c,d,e}/bar'))
.add('minimatch', () => minimatch.makeRe('foo/{a,b,c,d,e}/bar'))
.run();
bench('expand - nested sets (expanded)')
.add(' braces', () => braces.expand('foo/{a,b,{x,y,z}}/bar'))
.add('minimatch', () => minimatch.braceExpand('foo/{a,b,{x,y,z}}/bar'))
.run();
bench('expand - nested sets (optimized for regex)')
.add(' braces', () => braces.compile('foo/{a,b,c,d,e,{x,y,z}}/bar'))
.add('minimatch', () => minimatch.makeRe('foo/{a,b,c,d,e,{x,y,z}}/bar'))
.run();