Shared Regex vs per call Regex

JavaScript performance comparison

Test case created by MB

Preparation code

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?$/;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var x, i, ii;
for (i = 0; i < 1000; i++) {
x = r.test(dateText);
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);

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment