cronometro
Version:
Simple benchmarking suite powered by HDR histograms.
35 lines (34 loc) • 1.25 kB
JavaScript
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
if (typeof path === "string" && /^\.\.?\//.test(path)) {
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
});
}
return path;
};
/* c8 ignore start */
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
import { runWorker } from "./worker.js";
if (isMainThread) {
throw new Error('Do not run this file as main script.');
}
// Require the script to set tests
try {
const module = await import(__rewriteRelativeImportExtension(workerData.path, true));
if (typeof module === 'function') {
await module();
}
else if (typeof module.default === 'function') {
await module.default();
}
// Run the worker
runWorker(workerData, value => {
parentPort.postMessage({ type: 'cronometro.result', payload: value });
}, (code) => process.exit(code));
}
catch (error) {
process.nextTick(() => {
throw error;
});
}
/* c8 ignore stop */