regex v map

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var map = { a: true, b: true, c: true, d: true, e: true};
    map['z'] = true;
    map['9'] = true;
    map[')'] = true;
    map[' '] = true;
    map['1'] = true;
    map['3'] = true;
    map['7'] = true;
    map['5'] = true;
    map['#'] = true;
   
    var regex = /[a-e z91375#)]/;
   
    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