1

Does replacing console.log with console.debug in a quite heavy javascript application affect in any way the overall perfomance?

Thanks


Eg.

const startTime = new Date().getTime();
for (var id = 0; id < 100000000; id++) {
  console.log('test') // vs console.debug('test')
}
console.log(new Date().getTime()-startTime);

In Chrome nowadays console.debug logs only appears when level "Verbose" is selected so I assumed it would be slightly faster but it's actually slighty slower according to my benchmark results therefore I would appreciate some insights.

Thanks


UPDATE - Some heuristic results:

Using console.debug instead of console.log in long running processes, I noticed a slight (~5/10%) improvement in memory usage both in Chrome and Opera (latest version).

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • Well, you have some sample code there - why not just try running those two alternations? – CertainPerformance Aug 25 '18 at 05:22
  • Possible duplicate of [Difference between console.log() and console.debug()?](https://stackoverflow.com/questions/21876461/difference-between-console-log-and-console-debug) – Aram Grigoryan Aug 25 '18 at 05:25
  • 2
    you need performance in production code. thus the highest performance is to remove it when you push the code. learn to use breakpoints. – DragonKnight Aug 25 '18 at 05:25
  • @CertainPerformance According to my results console.debug is slower and that surprises me so I am asking for feedback. Thanks – Gabe Aug 25 '18 at 05:31
  • @DragonKnight Agree, logs are already removed in production. I would like to improve perfomance on a local environment. – Gabe Aug 25 '18 at 05:33
  • @AramGrigoryan this question is specific about perfomance and benchmarks, thanks. Also, that's an old question - in chrome now for example console.debug is not printed out by default (logs only appears when level "Verbose" is selected) so I assumed it would be slightly faster but it's actually slighty slower according to my results. – Gabe Aug 25 '18 at 05:44
  • 1
    I would think that if it does, it is negligible. I will say one of the benefits of using `console.debug` is you can fine-tune its use and turn it off and on. – Sam Orozco Aug 25 '18 at 06:01
  • 1
    while working in dev env using console.log vs console.debug will never make a difference. there are other things that affect performance much much much worse e.g. source maps – skyboyer Aug 25 '18 at 08:10

0 Answers0