ext-perf

Benchmark created on


Setup

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

function getExtension(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) => {   
	file.slice((file.lastIndexOf(".") - 1 >>> 0)+2);
});
ready
v2
vname .forEach((file) => {   
	file.slice((Math.max(0, file.lastIndexOf(".")) || Infinity) + 1);
});
ready
mio
vname .forEach((file) => { getExtension(file);});
ready

Revisions

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