Compare Regex to JS

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://documentcloud.github.com/underscore/underscore-min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var tests = [
    "abc",
    "abcdefghijk",
    "abdfkmnpstvxz",
    "cxy",
    "cdklstxy",
    "bfrtw",
    "a b c",
    "acg jko pr",
    "a z",
    "v  z",
    "a  b cdefg kl",
    "uv xyz",
    "ab de gh",
    "x yz",
    "abcdefghijklmnopqrstuvwxyz",
    "abbc",
    "abcb",
    "a bcdjkrza",
    "qwerty",
    "zyxcba",
    "abcdfe",
    "ab c dfe",
    "a  z  a",
    "asdfg",
    "asd  f g",
    "poqwoieruytjhfg"
  ];

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
regex
var reg = /^a? *b? *c? *d? *e? *f? *g? *h? *i? *j? *k? *l? *m? *n? *o? *p? *q? *r? *s? *t? *u? *v? *w? *x? *y? *z?$/;

for(var i=0; i<tests.length; i++) {
  reg.test(tests[i]);
}
pending…
vanillaJS
var alphabetical = function(str) {
  var last = " ";
  for(var i=0; i<str.length; i++) {
    if(str[i] == ' ') continue;
    if(str[i] > last) {
      last = str[i];
    } else {
      return false;
    }
  }
  return true;
}

for(var i=0; i<tests.length; i++) {
  alphabetical(tests[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.

0 Comments