get image by getElementById vs document.images

JavaScript performance comparison

Test case created by Cezary Tomczyk

Preparation code

<script>
var img = document.createElement('img');
img.id = 'testimg';
img.width = '84';
img.height = '24';
img.src = 'http://static.bbci.co.uk/frameworks/barlesque/2.48.3/desktop/3.5/img/blq-blocks_grey_alpha.png';
document.body.appendChild(img);
var img1, img2, imgs = document.images;
</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
getElementById
img1 = document.getElementById('testimg');
pending…
document.images
img2 = imgs['testimg'];
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