8

Is that possible to put the time of an action in second instead of milisecond with console time ?

Here is my code :

  console.log('start load cache');
  console.time('cache load ok executed in')
  // my loading from mongo
  console.timeEnd('cache load ok executed in')

What I get:

start load cache
cache load ok executed in: 47245.049ms

What I would like:

start load cache
cache load ok executed in: 47.245s

Thanks !

2
  • 3
    sec / 1000 = ms, just divide it by 1000 Commented Nov 19, 2018 at 16:11
  • @VelimirTchatchevsky You should check your units or the operator because one second has slightly more than 0.001 milliseconds... Commented Nov 19, 2018 at 16:19

2 Answers 2

14

console.time won't work for that, but you can always do it yourself:

console.log('start load cache');
const before = Date.now();
// my loading from mongo
const after = Date.now();
console.log('cache load ok executed in', (after - before) / 1000);
Sign up to request clarification or add additional context in comments.

Comments

1

you can create a custom function and use it as below.

var getExecutionTime = function (fn) {
    var from = Date.now();
    fn();
    var to = Date.now();

    return to - from;
}

var execTime = getExecutionTime(function(){
// my loading from mongo
});
console.log("execution time in milisecond:", execTime/1000);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.