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);
});
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);
});
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