SVG Images Swapout

JavaScript performance comparison

Test case created by Jeremy Worboys

Preparation code

<img src="/images/test.svg">
<img src="/images/test.png">
<img src="/images/test.svg">
<img src="/images/test.jpg">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.png">
<img src="/images/test.svg">
<img src="/images/test.jpg">
<img src="/images/test.png">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.jpg">
<img src="/images/test.svg">
<img src="/images/test.png">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.jpg">
<img src="/images/test.svg">
<img src="/images/test.jpg">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.svg">
<img src="/images/test.png">
<img src="/images/test.svg">

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Split
var images = document.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
  var src = images[i].src.split(".");
  images[i].src = src[0] + ".png";
}
pending…
Slice
var svg = /\.svg$/;
var images = document.getElementsByTagName('img');
for (var i = images.length - 1, src; i >= 0; i--) {
  src = images[i].src;
  if (src.match(svg)) images[i].src = src.slice(0, -4) + '.png';
}
pending…

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

Compare results of other browsers

0 comments

Add a comment