-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
bench.js
48 lines (40 loc) · 1.98 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
/* global bench, suite */
import fs from 'node:fs';
import {matcher, isMatch} from './index.js';
const fixture = fs.readFileSync('fixture.txt', 'utf8');
const paragraph = fixture.split('\n')[0];
const sentence = fixture.split('.')[0];
suite('matcher() - sentence', () => {
bench('multiple patterns', () => matcher(sentence.split(' '), ['*bar', '!foo', '!*oo']));
bench('zero or more chars', () => matcher(sentence.split(' '), ['*foo']));
bench('negation', () => matcher(sentence.split(' '), ['!foo']));
bench('negation zero or more', () => matcher(sentence.split(' '), ['!*foo']));
});
suite('isMatch() - sentence', () => {
bench('sentence', () => isMatch(sentence, '*bar*'));
});
suite('matcher() - paragraph', () => {
bench('multiple patterns', () => matcher(paragraph.split(' '), ['*bar', '!foo', '!*oo']));
bench('zero or more chars', () => matcher(paragraph.split(' '), ['*foo']));
bench('negation', () => matcher(paragraph.split(' '), ['!foo']));
bench('negation zero or more', () => matcher(paragraph.split(' '), ['!*foo']));
});
suite('isMatch() - paragraph', () => {
bench('test', () => isMatch(paragraph, '*bar*'));
});
suite('matcher() - fixture', () => {
bench('multiple patterns', () => matcher(fixture.split(' '), ['*bar', '!foo', '!*oo']));
bench('zero or more chars', () => matcher(fixture.split(' '), ['*foo']));
bench('negation', () => matcher(fixture.split(' '), ['!foo']));
bench('negation zero or more', () => matcher(fixture.split(' '), ['!*foo']));
});
suite('isMatch() - fixture', () => {
bench('test', () => isMatch(fixture, '*bar*'));
});
suite('matcher({allPatterns}) - fixture', () => {
const options = {allPatterns: true};
bench('multiple patterns', () => matcher(fixture.split(' '), ['*bar', '!foo', '!*oo'], options));
bench('zero or more chars', () => matcher(fixture.split(' '), ['*foo'], options));
bench('negation', () => matcher(fixture.split(' '), ['!foo'], options));
bench('negation zero or more', () => matcher(fixture.split(' '), ['!*foo'], options));
});