regex v map

JavaScript performance comparison

Test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var map = { a: 1, b: 2, c: 3, d: 4, e: 5};
    var regex = /[a-e]/;
   
    var test = 'the lazy dog jumped over the red fox';
    var len = test.length;
};
</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
map
var count = 0;
for (var i = 0; i < len; i++) {
  if (test[i] in map) count++;
}
pending…
regex
var count = 0;
for (var i = 0; i < len; i++) {
  if (regex.test(test[i])) count++;
}
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