Actually, console.log is a lot slower than an empty function. Running this jsPerf test on my Chrome 38 gives stunning results:
- when the browser console is closed, calling
console.logis about 10 000 times slower than calling an empty function, - and when the console is open, calling it is as much as 100 000 times slower.
Not that you’ll notice the performance lag if you have a reasonable number of console.… calls firing once (a hundred will take 2 ms on my install of Chrome – or 20 ms when the console is open). But if you log stuff to the console repeatedly – for instance, hooking it up through requestAnimationFrame – it can make things janky.
Update:
In this test I’ve also checked out the idea of a custom “hidden log” for production – having a variable which holds log messages, available on demand. It turns out to be
- about 1 000 times faster than the native
console.log, - and obviously 10 000 times faster if the user has his console open.