querySelectAll vs jQuery vs getElementById

by Valentin Radulescu

CSS

body{
    margin: 0;
    padding: 0;
}

JavaScript

var begin = new Date();
for(var i = 0; i < 10000; i++){
    var red = Math.round(Math.random() * 255).toString(16);
    var green = (Math.round(Math.random() * 255)).toString(16);
    var blue = (Math.round(Math.random() * 255)).toString(16);
    var elem = document.createElement('div');
    elem.style.width = '10px';
    elem.style.height = '10px';
    elem.style.backgroundColor = '#' + red + green + blue;
    elem.style.display = 'inline-block';
    elem.style.margin = '1px';
    elem.id = 'd'+i;
    document.body.appendChild(elem);
}

console.log(Math.abs(new Date() - begin));