Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is console.debug faster than console.log?

Here’s what I tried:

const log = () => {
    console.time("Log");
    console.log("Test");
    console.timeEnd("Log");
}

const debug = () => {
    console.time("Debug");
    console.debug("Test");
    console.timeEnd("Debug");
}

When I run these results are as follows:

Test
VM406:4 Log: 0.06396484375 ms
Test
VM500:4 Debug: 0.059814453125 ms

And most of the time I see debug having a slight edge on log. Is it just co-incidence or debug is actually faster than log? And if so should we just stop using log at all cases and use debug instead?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, the log level is handled as a string within the console object, and there is no reason to think that debug is faster than log.

The fact that trying to execute your code is likely to reproduce the output is due to the fact that log is executed before debug, and I can suppose that most of the internal objects of console gets cached by the JavaScript engine. For this reason, the second execution will always be a bit faster than the first

const log = () => {
    console.time("Log");
    console.log("Test");
    console.timeEnd("Log");
}

const debug = () => {
    console.time("Debug");
    console.debug("Test");
    console.timeEnd("Debug");
}

log();
debug();
const log = () => {
    console.time("Log");
    console.log("Test");
    console.timeEnd("Log");
}

const debug = () => {
    console.time("Debug");
    console.debug("Test");
    console.timeEnd("Debug");
}

debug();
log();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading