Verified Commit 19c9a04c authored by nagayama15's avatar nagayama15

Update the benchmark script

parent 22e43969
require("./testutils"); require("./testutils");
const stress = require("./stress"); const stress = require("./stress");
const WARM = 3;
const N = 10 + WARM;
(async () => { (async () => {
const runBench = dir => { const runBench = dir => {
const Ammo = require(`./${dir}/ammo.wasm`); const Ammo = require(`./${dir}/ammo.wasm`);
return new Promise(resolve => { return new Promise(resolve => {
console.error(`${dir}`);
// Wrap `Ammo()` by real `Promise` object because it returns just Promise-like object // Wrap `Ammo()` by real `Promise` object because it returns just Promise-like object
// and awaiting it acts buggy. // and awaiting it acts buggy.
Ammo().then(Ammo => { Ammo().then(Ammo => {
const durs = [];
for (let i = 0; i < N; i++) {
const dur = stress(Ammo); const dur = stress(Ammo);
durs.push(dur); resolve(dur);
console.error(dur);
}
resolve({ dir, durs });
}); });
}); });
}; };
...@@ -41,10 +31,10 @@ const N = 10 + WARM; ...@@ -41,10 +31,10 @@ const N = 10 + WARM;
"dist/ammo-3-fe8191b3" "dist/ammo-3-fe8191b3"
]; ];
const results = []; const row = [];
for (wasm of wasms) { const keys = [...wasms.keys()].sort(() => Math.random() - 0.5);
results.push(await runBench(wasm)); for (const i of keys) {
row[i] = await runBench(wasms[i]);
} }
console.log(row.join("\t"));
console.log(JSON.stringify(results));
})(); })();
const Crypto = require("crypto"); const Crypto = require("crypto");
const assert = require("assert"); const assert = require("assert");
const size = 1_000_000; const size = 10_000_000;
const rawData = Crypto.randomBytes(size); const rawData = Crypto.randomBytes(size);
(async function() { (async function() {
...@@ -49,19 +49,18 @@ const rawData = Crypto.randomBytes(size); ...@@ -49,19 +49,18 @@ const rawData = Crypto.randomBytes(size);
console.log(`deflated size: ${compressed.length}bytes`); console.log(`deflated size: ${compressed.length}bytes`);
console.log(`compression rate: ${(compressionRate * 100).toFixed(1)}%`); console.log(`compression rate: ${(compressionRate * 100).toFixed(1)}%`);
libs.forEach((Zlib, i) => { console.log(libPaths.join("\t"));
// Warming up
console.time(`Warm - ${libPaths[i]}`);
for (let i = 0; i < 10; i++) {
Zlib.deflate(rawData);
}
console.timeEnd(`Warm - ${libPaths[i]}`);
// Benchmark
console.time(`Benchmark - ${libPaths[i]}`);
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
Zlib.deflate(rawData); const keys = [...libs.keys()].sort(() => Math.random() - 0.5);
} const row = [];
console.timeEnd(`Benchmark - ${libPaths[i]}`);
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