29 lines
1.7 KiB
JavaScript
29 lines
1.7 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import crypto from "node:crypto";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const source = path.join(root, "freecad-source/build-web/configure/bin/FreeCADWebStartRuntimeProbe.wasm");
|
|
const directory = fs.mkdtempSync(path.join(root, "web/public/.copy-benchmark-"));
|
|
const results = [];
|
|
try {
|
|
const expected = crypto.createHash("sha256").update(fs.readFileSync(source)).digest("hex");
|
|
for (const [mode, flags] of [["copy", 0], ["reflink-required", fs.constants.COPYFILE_FICLONE_FORCE]]) {
|
|
const target = path.join(directory, "probe.wasm"), start = performance.now();
|
|
try {
|
|
fs.copyFileSync(source, target, flags);
|
|
const seconds = (performance.now() - start) / 1000;
|
|
const actual = crypto.createHash("sha256").update(fs.readFileSync(target)).digest("hex");
|
|
if (actual !== expected) throw Error("Artifact checksum mismatch");
|
|
results.push({ mode, seconds, checksumMatches: true });
|
|
} catch (error) {
|
|
if (error.code !== "ENOTSUP" && error.code !== "EOPNOTSUPP" && error.code !== "EXDEV") throw error;
|
|
results.push({ mode, seconds: (performance.now() - start) / 1000, supported: false, code: error.code });
|
|
} finally { fs.rmSync(target, { force: true }); }
|
|
}
|
|
const report = { generatedAt: new Date().toISOString(), source: path.relative(root, source), bytes: fs.statSync(source).size, results };
|
|
fs.writeFileSync(path.join(root, "docs/current/wasm-copy-benchmark.json"), JSON.stringify(report, null, 2) + "\n");
|
|
console.log(JSON.stringify(report));
|
|
} finally { fs.rmSync(directory, { recursive: true, force: true }); }
|