I hoping to benchmark how long a browser takes to take an image from memory and display it on the page, ideally just using JS.
My initial idea was to load a 4000x4000 image into a JS image object, and then time how long it takes to append the image to a div (and then remove it) 100 times. Will paste the script I'm using to do this below.
My problem is it seems to do the 100 iterations very fast, within 2ms, which seems faster than it should be able to do this. I'm guessing this is because of some sort of caching, or because the actual displaying is being handed off to a separate thread and this JS thread is able to proceed asynchronously.
Anyone know for sure what's going on? Can you suggest a better way of doing this?
Thanks!
<script>
var img = new Image();
img.src = "http://path/to/image.jpg";
img.onload = function() {
var div = document.getElementById('image');
var d, start, total;
d = new Date();
start = d.getTime();
for (i = 0; i < 100; i++) {
div.appendChild(img);
div.removeChild(img);
}
d = new Date();
total = d.getTime() - start;
console.log(total);
};
</script>
<div id="image"></div>