slice things vs regexp things

Benchmark created by Aymeric on


Preparation HTML

<script>
  var str = 'foo <span class=ms-formvalidation>*</span>';
  var str2 = 'foo <span class="ms-formvalidation">*</span>';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
slice
var res = str2.slice(0,-39);
if (res.charAt(res.length-2) == ' ' && res.charAt(res.length-1)=='<') res=res.slice(0,-2);
ready
regexp
var res=str2.replace(/(<([^>]+)>)/ig,"").slice(0,-2);
ready

Revisions

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

  • Revision 1: published by Aymeric on