Measure and output the time conversion takes

This commit is contained in:
Domenic Denicola 2020-11-07 18:46:56 -05:00
commit f70ba64629

View file

@ -1,6 +1,7 @@
"use strict";
const path = require("path");
const fs = require("fs").promises;
const { performance } = require("perf_hooks");
const workerpool = require("workerpool");
const cliProgress = require("cli-progress");
@ -11,9 +12,12 @@ module.exports = async (cachePath, manifestPath, contentPath, book, concurrentJo
console.log("Converting raw downloaded HTML to EPUB chapters");
const progress = new cliProgress.SingleBar({
stopOnComplete: true,
clearOnComplete: true
clearOnComplete: true,
format: " {bar} {percentage}% | {time} | {value}/{total}"
}, cliProgress.Presets.shades_classic);
progress.start(chapters.length, 0);
const start = performance.now();
progress.start(chapters.length, 0, { time: " " });
const poolOptions = {};
if (concurrentJobs !== undefined) {
@ -30,7 +34,8 @@ module.exports = async (cachePath, manifestPath, contentPath, book, concurrentJo
warnings.push(...await pool.exec("convertChapter", [chapter, book, inputPath, outputPath]));
progress.increment();
const time = String(Math.round((performance.now() - start) / 1000)).padStart(3) + " s";
progress.increment({ time });
}));
pool.terminate();
@ -39,5 +44,5 @@ module.exports = async (cachePath, manifestPath, contentPath, book, concurrentJo
console.warn(warning);
}
console.log("All chapters converted");
console.log(`All chapters converted in ${Math.round((performance.now() - start) / 100) / 10} seconds`);
};