0

I have code that writes data to a file, how can it be done to show how much time it took to write a file?

const fs = require("fs");
fs.writeFile('./text.json', JSON.stringify(m), (err) => {
    if (err) console.log(err);
});
Maks
  • 11
  • 1

1 Answers1

-1

you can do something like this:

/*

time from unix epoch in milliseconds = new Date().getTime();

*/


const currentTime = new Date().getTime();

// Some operation here

const timeNow = new Date().getTime();

const timeTookInMilliseconds = timeNow - currentTime;

You can read more here: MDN

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '22 at 18:18