Verified Commit 19c9a04c authored by nagayama15's avatar nagayama15

Update the benchmark script

parent 22e43969
require("./testutils");
const stress = require("./stress");
const WARM = 3;
const N = 10 + WARM;
(async () => {
const runBench = dir => {
const Ammo = require(`./${dir}/ammo.wasm`);
return new Promise(resolve => {
console.error(`${dir}`);
// Wrap `Ammo()` by real `Promise` object because it returns just Promise-like object
// and awaiting it acts buggy.
Ammo().then(Ammo => {
const durs = [];
for (let i = 0; i < N; i++) {
const dur = stress(Ammo);
durs.push(dur);
console.error(dur);
}
resolve({ dir, durs });
const dur = stress(Ammo);
resolve(dur);
});
});
};
......@@ -41,10 +31,10 @@ const N = 10 + WARM;
"dist/ammo-3-fe8191b3"
];
const results = [];
for (wasm of wasms) {
results.push(await runBench(wasm));
const row = [];
const keys = [...wasms.keys()].sort(() => Math.random() - 0.5);
for (const i of keys) {
row[i] = await runBench(wasms[i]);
}
console.log(JSON.stringify(results));
console.log(row.join("\t"));
})();
const Crypto = require("crypto");
const assert = require("assert");
const size = 1_000_000;
const size = 10_000_000;
const rawData = Crypto.randomBytes(size);
(async function() {
......@@ -49,19 +49,18 @@ const rawData = Crypto.randomBytes(size);
console.log(`deflated size: ${compressed.length}bytes`);
console.log(`compression rate: ${(compressionRate * 100).toFixed(1)}%`);
libs.forEach((Zlib, i) => {
// Warming up
console.time(`Warm - ${libPaths[i]}`);
for (let i = 0; i < 10; i++) {
Zlib.deflate(rawData);
}
console.timeEnd(`Warm - ${libPaths[i]}`);
console.log(libPaths.join("\t"));
// Benchmark
console.time(`Benchmark - ${libPaths[i]}`);
for (let i = 0; i < 100; i++) {
Zlib.deflate(rawData);
}
console.timeEnd(`Benchmark - ${libPaths[i]}`);
});
for (let i = 0; i < 100; i++) {
const keys = [...libs.keys()].sort(() => Math.random() - 0.5);
const row = [];
keys.forEach(i => {
const start = Date.now();
libs[i].deflate(rawData);
const end = Date.now();
row[i] = end - start;
});
console.log(row.join("\t"));
}
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment