\s\s*

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script>
var arr;
window.onload=function(){ arr = document.documentElement.innerHTML.replace(/>/g,"<").split("<"); }
var singleRegexp = /^\s+|\s+$/g;
var doubleRegexp0 = /^\s+/;
var doubleRegexp1 = /\s+$/;
</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
1 regex
for(var idx =0;idx<arr.length;idx++)
  arr[idx].replace(singleRegexp , '');
pending…
2 regexes
for(var idx =0;idx<arr.length;idx++)
  arr[idx].replace(doubleRegexp0, '').replace(doubleRegexp1, '')
pending…
2 regexes (rev)
for(var idx =0;idx<arr.length;idx++)
  arr[idx].replace(doubleRegexp1, '').replace(doubleRegexp0, '')
pending…
1 regex recreated
for(var idx =0;idx<arr.length;idx++)
  arr[idx].replace(/^\s+|\s+$/g, '');
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