regex vs. split

Benchmark created by lifesinger on


Preparation HTML

<script>
  function dirname(path) {
   var s = path.split('/').slice(0, -1).join('/');
   return s ? s : '.';
  }
  
  function dirname2(path) {
   var s = ('./' + path).replace(/(.*)?\/.*/, '$1').substring(2);
   return s ? s : '.';
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
split
dirname('a/b/c.js');
dirname('a/b/c');
dirname('a/b/c/');
dirname('d.js');
ready
regex
dirname2('a/b/c.js');
dirname2('a/b/c');
dirname2('a/b/c/');
dirname2('d.js');
ready

Revisions

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