1

I'm trying to measure time taken by a function to execute in JS. When I try to console.log() the elapsed time, some blue numbers appear in the console and some of the logs are gone.
When I counted the appeared number, it matched with the number of lines of skipped log.

enter image description here

I'm sure you can notice the problem at the right part of screenshot.

I would like the console to show all of the logs.

Is there anything I can do? BTW, the browser is Firefox 58.0b8. (Developer Edition)

ibrahim mahrir
  • 31,174
  • 5
  • 48
  • 73
  • 1
    There should be a setting for that in the devtools – Bergi Dec 04 '17 at 20:08
  • related: [Chrome debugger - how to turn off console.log message grouping?](https://stackoverflow.com/q/25706235/1048572) – Bergi Dec 04 '17 at 20:15
  • 1
    There's nothing skipped. These blue numbers are just a shorthand to tell you, that the very same value has been logged x times in a row. It's just a more compact output, than actually printing the same value in x consecutive rows. – Thomas Dec 04 '17 at 20:17
  • @Bergi That was what I wanted, but Firefox doesn't seem to have that setting. Thanks for the help. – Jeong Wook Park Dec 04 '17 at 20:23
  • @Thomas I wanted to take a screenshot of the log, but the line wasn't sorted(sometimes 8 lines, sometimes 7 lines...). Anyway, thanks for the comment. – Jeong Wook Park Dec 04 '17 at 20:24

3 Answers3

0

Rather than do console.log, why don't you write the time to an array a print that at the end of the test?

Glitcher
  • 1,078
  • 6
  • 14
0

Not sure, if this will serve your purpose but this is a workaround not a solution provided by any browser.

You can add a wrapper function for console.log like below

function logToConsole(number) {
  var randomNumber = Math.floor(Math.random() * 6) + 1; 
  console.log(number.toString() + Array(randomNumber).join(" "));
}

Here, each time console.log is called, it is padded with a random number between 1 and 6. (You can also increase the range, if you feel that there is a chance for error)

Complete example below.

function logToConsole(number) {
  var randomNumber = Math.floor(Math.random() * 6) + 1; 
  console.log(number.toString() + Array(randomNumber).join(" "));
}

logToConsole(0.1111);
logToConsole(0.1111);
logToConsole(0.1111);
logToConsole(0.1111);
logToConsole(0.1111);
Vipin Kumar
  • 6,441
  • 1
  • 19
  • 25
0

There are benchmarking methods in console that have very high accuracy. You can use console.time(key) and console.timeEnd(key).

https://developer.mozilla.org/en-US/docs/Web/API/Console/time

// kick off 
console.time('asdf')

// later
console.timeEnd('asdf')

// VM18707:1 asdf: 2077.59716796875ms

Even calling timeEnd immediately will yield different results, so it's not likely to have multiple consecutive equal results with a more complex script.

posit labs
  • 8,951
  • 4
  • 36
  • 66