mirror of
https://github.com/LukeHagar/wasm-overhead-research.git
synced 2025-12-06 04:22:06 +00:00
Initial commit: JavaScript to WebAssembly compilation comparison
- 5 different JS-to-WASM implementations analyzed - QuickJS (283KB) and Javy Static (519KB) are Wasmer-compatible - Comprehensive size analysis and runtime compatibility testing - Complete documentation and build automation - Wasmer v6.1.0-rc.2 dynamic linking analysis included
This commit is contained in:
65
measure-gzipped-sizes.js
Normal file
65
measure-gzipped-sizes.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { readFile, writeFile } from "fs/promises";
|
||||
import { gzip } from "zlib";
|
||||
import { promisify } from "util";
|
||||
import { glob } from "glob";
|
||||
|
||||
const gzipAsync = promisify(gzip);
|
||||
|
||||
async function measureGzippedSize(filePath) {
|
||||
try {
|
||||
const data = await readFile(filePath);
|
||||
const compressed = await gzipAsync(data);
|
||||
return {
|
||||
original: data.length,
|
||||
gzipped: compressed.length,
|
||||
ratio: ((1 - compressed.length / data.length) * 100).toFixed(1),
|
||||
};
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function measureAllWasmFiles() {
|
||||
console.log("📊 Measuring gzipped sizes of all WASM binaries...\n");
|
||||
|
||||
// Find all WASM files
|
||||
const wasmFiles = await glob("**/*.wasm", { ignore: "node_modules/**" });
|
||||
|
||||
const results = [];
|
||||
|
||||
for (const file of wasmFiles.sort()) {
|
||||
const sizes = await measureGzippedSize(file);
|
||||
if (sizes) {
|
||||
results.push({
|
||||
file,
|
||||
...sizes,
|
||||
});
|
||||
|
||||
console.log(`${file}:`);
|
||||
console.log(` Original: ${(sizes.original / 1024).toFixed(0)}KB`);
|
||||
console.log(
|
||||
` Gzipped: ${(sizes.gzipped / 1024).toFixed(0)}KB (${
|
||||
sizes.ratio
|
||||
}% compression)`
|
||||
);
|
||||
console.log("");
|
||||
}
|
||||
}
|
||||
|
||||
// Generate summary table
|
||||
console.log("=== GZIPPED SIZE SUMMARY ===\n");
|
||||
console.log("| File | Original (KB) | Gzipped (KB) | Compression |");
|
||||
console.log("|------|---------------|--------------|-------------|");
|
||||
|
||||
for (const result of results) {
|
||||
const originalKB = (result.original / 1024).toFixed(0);
|
||||
const gzippedKB = (result.gzipped / 1024).toFixed(0);
|
||||
console.log(
|
||||
`| ${result.file} | ${originalKB} | ${gzippedKB} | ${result.ratio}% |`
|
||||
);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
measureAllWasmFiles().catch(console.error);
|
||||
Reference in New Issue
Block a user