parseInt vs regex

JavaScript performance comparison

Test case created by lonesomeday

Info

http://stackoverflow.com/questions/4646641/javascript-regular-expressions/4646714#4646714

Preparation code

<script>
  var hours = ['48', '83', '2', '0', '24'],
      regex = /^([1-9]|[1-5][0-9]|60)$/;
</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
parseInt
for (var i = hours.length; i--;) {
 parseInt(hours[i]);
}
pending…
regex
for (var i = hours.length; i--;) {
 regex.test(hours[i]);
}
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