Test regex vs split

Benchmark created by epascarello on


Preparation HTML

<script>
  var str="someone@example.com";
  var reMatch = /^([^@]*)@/;
  var reReplace = /@.*$/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
reg exp - match
var nameMatch = str.match(reMatch)[1];
//var name = nameMatch ? nameMatch[1] : null;
ready
reg exp2 - replace
var nameReplace = str.replace(reReplace);
//var name = str!==nameReplace ? nameReplace : null;
ready
split
var nameParts = str.split("@")[0];
//var name = nameParts.length==2 ? nameParts[0] : null;
ready

Revisions

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