Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much does it cost in terms of performance to use console.log in nodejs and in browsers?

Let's say you log certain things on your nodejs app or on a browser. How much does this affect performance / CPU usage vs removing all these logs in production?

I'm not asking because I'm just curious how much "faster" would things run without it so I can take that into account when developing.

like image 592
davvilla Avatar asked Dec 01 '11 04:12

davvilla


3 Answers

It can cost a lot, specially if your application is hardly based on a loop, like a game or a GUI app that gets updated in real time.

Once I developed an educational physics app using <canvas>, and with logs activated withing the main application loop the frame rate easily dropped from 60fps to 28fps! That was quite catastrophic for the user experience.

Overall tip for browser applications is: Do not use console.log() in production for loop based applications specially the ones that need to update a graphical interface within the loop.

like image 151
marcio Avatar answered Sep 20 '22 10:09

marcio


For Node: is node.js' console.log asynchronous?

I imagine it's implemented similar in some of the browsers.

like image 41
Justin Thomas Avatar answered Sep 18 '22 10:09

Justin Thomas


I'm not familiar with node.js, however it's typically not a good thing to log anything except critical errors in a production environment. Unless node.js offers a logging utility like log4j, you should look at something like log4js (haven't used, just first google response)

like image 28
hafichuk Avatar answered Sep 18 '22 10:09

hafichuk