Extract file extension

JavaScript performance comparison

Test case created by VisioN

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var filename = "name.with.many.dots.myext";

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
VisioN #1 (long)
var extension = filename.substr((Math.max(0, filename.lastIndexOf(".")) || Infinity) + 1);
pending…
VisioN #2 (short)
var extension = filename.substr((~-filename.lastIndexOf(".") >>> 0) + 2);
pending…
Tom
var extension = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename) : undefined;
pending…
wallacer (popular)
var extension = filename.split(".").pop();
pending…
PhiLho
var extension = /^.+\.([^.]+)$/.exec(filename);
extension = extension == null ? "" : extension[1];
pending…

Compare results of other browsers

Revisions

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

0 Comments