regex vs. split (v3)

Revision 3 of this benchmark created by lifesinger on


Preparation HTML

<script>
  
  
  function dirname3(path) {
    var s = (path).match(/.*(?=\/.*$)/);
    return (s ? s[0] : '.') + '/';
  }

  var RE = /.*(?=\/.*$)/;
  function dirname4(path) {
    var s = (path).match(RE);
    return (s ? s[0] : '.') + '/';
  }

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
inline
dirname3('a/b/c.js');
dirname3('a/b/c');
dirname3('a/b/c/');
dirname3('d.js');
ready
cache
dirname4('a/b/c.js');
dirname4('a/b/c');
dirname4('a/b/c/');
dirname4('d.js');
ready

Revisions

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