Shared Regex vs per call Regex

JavaScript performance comparison

Test case created by MB

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var dateText = new Date().toISOString();
    var r = /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?([\+-]\d{2}\:\d{2})?Z?$/;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Shared
var x, i, ii;
for (i = 0; i < 1000; i++) {
x = r.test(dateText);
}
pending…
Per Call
var x, i, ii;
for (i = 0; i < 1000; i++) {
x = /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?([\+-]\d{2}\:\d{2})?Z?$/.test(dateText);
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment