After numerous tests, this function provides the most performant way to iterate over all the elements in the DOM:
function walkTheDom() {
var items = document.getElementsByTagName("*");
var i=items.length;
var item;
do
{
item = items[i];
//Do something with item
}
while (--i);
}