Skip to content

Commit 63273f9

Browse files
committed
Add constructor with flag x to perf tests. slevithan#129
1 parent 3741361 commit 63273f9

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/perf/perf.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// Expose as global
4444
window.run = function() {
4545
log('Testing XRegExp ' + XRegExp.version + '.\n');
46-
log('Sit back and relax; this might take a while.\n');
46+
log('Sit back and relax. This might take a while.\n');
4747
suites[0].run();
4848
};
4949

@@ -64,25 +64,36 @@
6464
{
6565
name: 'Constructor with long pattern',
6666
pattern: XRegExp('\\p{L}').source
67+
},
68+
{
69+
name: 'Constructor with x flag, whitespace, and comments',
70+
pattern: '\n # comment\n # comment\n',
71+
flags: 'x'
6772
}
6873
];
6974

7075
configs.forEach(function(config) {
71-
suites.push(Benchmark.Suite(config.name)
76+
var flags = config.flags || '';
77+
var allFlagsNative = /^[gimuy]*$/.test(flags);
78+
79+
var suite = Benchmark.Suite(config.name)
7280
.add('XRegExp with pattern cache flush', function() {
73-
XRegExp(config.pattern, 'g');
81+
XRegExp(config.pattern, flags);
7482
XRegExp.cache.flush('patterns');
7583
})
7684
.add('XRegExp', function() {
77-
XRegExp(config.pattern, 'g');
85+
XRegExp(config.pattern, flags);
7886
})
7987
.add('XRegExp.cache', function() {
80-
XRegExp.cache(config.pattern, 'g');
81-
})
82-
.add('RegExp', function() {
83-
new RegExp(config.pattern, 'g');
84-
})
85-
);
88+
XRegExp.cache(config.pattern, flags);
89+
});
90+
if (allFlagsNative) {
91+
suite.add('RegExp', function() {
92+
new RegExp(config.pattern, flags);
93+
});
94+
}
95+
96+
suites.push(suite);
8697
});
8798
}());
8899

0 commit comments

Comments
 (0)