regex v map

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

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;

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 count = 0;
for (var i = 0; i < len; i++) {
  if (test[i] in map) count++;
var count = 0;
for (var i = 0; i < len; i++) {
  if (regex.test(test[i])) count++;

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment