Commit 4746dc8b authored by nagayama15's avatar nagayama15

Implement bench

parent 0d5db91c
(async function() {
const Zlib = await require('./zlib').initialize('./zlib-sample.wasm');
const Crypto = require('crypto');
const assert = require('assert');
const rawData = Buffer.from([...Array(10000).keys()]);
const compressedData = Zlib.deflate(rawData);
const uncompressedData = Zlib.inflate(compressedData);
const size = 1_000_000;
const rawData = Crypto.randomBytes(size);
console.log(uncompressedData.equals(rawData));
(async function () {
const libPaths = [
'./zlib-sample.wasm',
];
const libs = await Promise.all(libPaths.map(async path => await require('./zlib').initialize(path)));
// Validation
libs.forEach((Zlib, i) => {
assert.deepEqual(Zlib.inflate(Zlib.deflate(rawData)), rawData, libPaths[i]);
});
// Warming up
libs.forEach((Zlib, i) => {
console.time(`Warm - ${libPaths[i]}`);
for (let i = 0; i < 5; i++) {
Zlib.deflate(rawData);
}
console.timeEnd(`Warm - ${libPaths[i]}`);
});
// Benchmark
libs.forEach((Zlib, i) => {
console.time(`Benchmark - ${libPaths[i]}`);
for (let i = 0; i < 100; i++) {
Zlib.deflate(rawData);
}
console.timeEnd(`Benchmark - ${libPaths[i]}`);
});
}());
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