-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Description
The Problem
I am trying to output time taken in seconds using the built in console.time()
and console.timeEnd()
functions.
Currently, my code and output looks like this:
console.time('Time taken');
// do things
console.timeEnd('Time taken');
Output: Time taken: 34239.098ms
The Solution
I would like to be able to pass in an optional parameter to console.timeEnd()
to be able to output the results in different units of time rather than milliseconds.
Example:
console.time('Time taken');
// do things
console.timeEnd('Time taken', 's'); // or 'ms', 'm', 'h', 'd'...
Output: Time taken: 34.239s
Current Alternative
This is the best alternative that I've currently found:
const begin = Date.now();
// do things
const end = Date.now();
const elapsedTime = (end-begin) / 1000;
console.log(`Time taken: ${elapsedTime}s`);
Output: Time taken: 34.239s
Conclusion
Normally I do use milliseconds with my output - and it should remain the default. However I have come across numerous asynchronous processes I'd like to easily measure final time for. Reading 12168532.35ms instead of 3.38h is slightly more difficult.
Thanks for your consideration!
Metadata
Metadata
Assignees
Labels
consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.