ext-perf (v2)

Revision 2 of this benchmark created on


Setup

let ext = ""
let fname = "name.txt"
let vname = ["",
	"name",
	"name.txt",
	".htpasswd",
	"name.with.many.dots.myext"
]

function v1(fname){
	return fname.slice((fname.lastIndexOf(".") - 1 >>> 0)+2);
}

function v2(fname){
	return fname.slice((Math.max(0, fname.lastIndexOf(".")) || Infinity) + 1);
}

function vmine(fname) {
  let len = fname.length;
  for (let i = len - 1; i >= 0; i--) {
    if (fname[i] == '.') {
      if (i > 0) return fname.slice(i);
      else return '';
      break;
    }
  }

  return '';
}

Test runner

Ready to run.

Testing in
TestOps/sec
v1
vname.forEach((file) => { v1(file); });
ready
v2
vname .forEach((file) => { v2(file); });
ready
mio
vname .forEach((file) => { vmine(file);});
ready

Revisions

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