在nodejs和浏览器中使用console.log在性能方面花了多少钱?

时间:2020-12-26 16:56:20

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?

假设您在nodejs应用程序或浏览器上记录某些内容。与生产中删除所有这些日志相比,这会影响性能/ CPU使用量多少?

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.

我不是在问,因为我只是好奇没有它会有多快“运行”所以我可以在开发时考虑到这一点。

3 个解决方案

#1


6  

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

对于Node:node.js'console.log是异步的吗?

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

我想它在某些浏览器中的实现方式类似。

#2


5  

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.

它可能会花费很多,特别是如果您的应用程序几乎不基于循环,如游戏或实时更新的GUI应用程序。

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.

一旦我使用 开发了一个教育物理应用程序,并且使用主应用程序循环激活日志,帧速率很容易从60fps降至28fps!这对用户体验来说是非常灾难性的。

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.

浏览器应用程序的总体提示是:不要在生产中使用console.log()来进行基于循环的应用程序,特别是那些需要在循环中更新图形界面的应用程序。

#3


1  

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)

我不熟悉node.js,但是除了生产环境中的关键错误之外,记录任何东西通常都不是一件好事。除非node.js提供像log4j这样的日志记录实用程序,你应该看看像log4js这样的东西(没用过,只是第一次google响应)

#1


6  

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

对于Node:node.js'console.log是异步的吗?

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

我想它在某些浏览器中的实现方式类似。

#2


5  

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.

它可能会花费很多,特别是如果您的应用程序几乎不基于循环,如游戏或实时更新的GUI应用程序。

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.

一旦我使用 开发了一个教育物理应用程序,并且使用主应用程序循环激活日志,帧速率很容易从60fps降至28fps!这对用户体验来说是非常灾难性的。

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.

浏览器应用程序的总体提示是:不要在生产中使用console.log()来进行基于循环的应用程序,特别是那些需要在循环中更新图形界面的应用程序。

#3


1  

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)

我不熟悉node.js,但是除了生产环境中的关键错误之外,记录任何东西通常都不是一件好事。除非node.js提供像log4j这样的日志记录实用程序,你应该看看像log4js这样的东西(没用过,只是第一次google响应)