Array's reverse vs simple arithmethic I was asked to print numbers from 100 to 1 in a for loop with the index starting from 1. I came up with this solution:

var a = [];

for(var i = 1; i &lt;= 100; i++) {
    a.push(i);
}

console.log(a.reverse());


I was thinking of a better way of doing this after the interview and came up with this

for(var i = 1; i &lt;= 100; i++) {
    console.log((100-i)+1);
}


Now what blows my mind is, jsperf.com's test indicates the former is faster. How is this even possible? Creating an array, pushing something into it and reversing it before printing definitely seems slower than simple arithmetic. Could anyone help me understand this?
It turns out accessing console take's more time than pushing a value in an array. Console.log is indeed implemented as a synchronous function (next print starts only after last print finishes).
Meaning, there is no buffering system. The program goes to blocking state until console.log() finish printing, everytime.
Performance difference in above two cases is due to the difference in the number of console.log() call.