Сохраните время до запуска, затем посмотрите, когда оно заканчивается
const readVideoFromDisc = (videoName, fileName) => {
return new Promise((resolve, reject) => {
const startTime = Date.now();
fs.readFile(BASE_FOLDER + "/" + videoName + "/" + fileName, (
err,
buf
) => {
const totalReadingTime = Date.now() - startTime;
console.log(`Reading the file took ${totalReadingTime}ms`);
// store files in redis buffer
if (err) {
reject(err);
}
console.log("read disc", fileName);
resolve(buf);
});
});
};
Кроме того, вы можете превратить ваш код в:
const readVideoFromDisc = async(videoName, fileName) => {
const startTime = Date.now();
const buf = util.promisify(fs.readFile)(`${BASE_FOLDER}/${videoName}/${fileName}`);
const totalReadingTime = Date.now() - startTime;
console.log(`Reading the file took ${totalReadingTime}ms`);
console.log("read disc", fileName);
return buf;
};