regex vs spllit

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var text = "90,71,h1,t67;89,71,h-1;88,71,h1;87,71,h1;86,71,h1;85,71,h1;84,71,h1;83,71,h1;82,71,h1;81,71,h1;80,71,h1;79,71,h1;78,71,h1;77,71,h1;76,71,h1;75,71,h1;74,71,h1;73,71,h1;72,71,h1;71,71,h1;70,71,h1;69,71,h1;68,71,h1;67,71,h1;66,71,h1,t5;65,71,h1;64,71,h1;63,71,h1;62,71,h1;61,71,h1;60,71,h1;60,70,h1;60,69,h1;59,69,h1;58,69,h1;57,69,h1;56,69,h1;56,68,h1;56,67,h1;55,67,h1;54,67,h1;53,67,h1;52,67,h1;51,67,h1;50,67,h1;49,67,h1;48,67,h1;48,66,h1;48,65,h1;48,64,h1;48,63,h1;47,63,h1;46,63,h1;45,63,h1;45,62,h1;45,61,h1,t53;45,60,h1;44,60,h1;44,59,h1;44,58,h1;44,57,h-1;44,56,h1;43,56,h1;43,55,h1;42,55,h1;42,54,h1;42,53,h1;42,52,h1;42,51,h1;42,50,h1;42,49,h1;42,48,h1;41,48,h1;41,47,h1;41,46,h1;41,45,h1;40,45,h1;40,44,h1;40,43,h-1;40,42,h1;40,41,h1;39,41,h1;38,41,h1;37,41,h1;37,40,h1;37,39,h1;37,38,h1;36,38,h1;36,37,h1;36,36,h1;35,36,h1;34,36,h1;33,36,h1;33,35,h1;33,34,h1;33,33,h1;33,32,h1;33,31,h1;33,30,h1;33,29,h1;33,28,h1;33,27,h1;33,26,h1;33,25,h1;33,24,h1;33,23,h1;33,22,h1;33,21,h1;33,20,h1;33,19,h1;33,18,h1;33,17,h1;33,16,h1;33,15,h1;33,14,h1;33,13,h1;33,12,h1;32,12,h1;31,12,h1;31,11,h1;31,10,h1;30,10,h1;29,10,h1;29,9,h1,t3;28,9,h1;27,9,h2;26,9,h2;25,9,h3;24,9,h3;23,9,h3";
   
    var regex = /([\d]*?),([\d]*?),((h)(-?[\d]*?))?,?((t)(-?[\d]*?))?(?=\;)/g;
};
</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
regex
var match = regex.exec(text);
while (match != null) {

  var x = match[1];
  var y = match[2];

var h,t;

if( match[4]==="h"){
h=match[5];
}else if(match[6]==="t"){
t=match[7];
}
  match = regex.exec(text);
}
pending…
split
        var res = text.split(";");

        for (var q = 0; q < res.length; q++) {

          var c = res[q].split(",");
          var x = c[0];
          var y = c[1];
var h,t;
var g=c[2].charAt(0);
     if(g==="h"){
        h=c[2].substring(1);
}else if(g==="t"){
        t=c[2].substring(1);
}


        }
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment