\d and 0-9 in regex

JavaScript performance comparison

Revision 2 of this test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var number = 123;
    var not_number = 'boo';
};
</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
with \d
if(/\d+/g.test(number)) { 
  //blah blah
}

if(/\d+/g.test(not_number)) {
  //blah blah
}
pending…
with 0-9
if(/[0-9]+/g.test(number)) { 
  //blah blah
}

if(/[0-9]+/g.test(not_number)) {
  //blah blah
}
pending…
with [0123456789]
if(/[0123456789]+/g.test(number)) { 
  //blah blah
}

if(/[0123456789]+/g.test(not_number)) {
  //blah blah
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment