Commit ec14f638 authored by nagayama15's avatar nagayama15

Improve bench

parent 68676602
...@@ -14,22 +14,27 @@ const rawData = Crypto.randomBytes(size); ...@@ -14,22 +14,27 @@ const rawData = Crypto.randomBytes(size);
const libs = await Promise.all(libPaths.map(async path => await require('./zlib').initialize(path))); const libs = await Promise.all(libPaths.map(async path => await require('./zlib').initialize(path)));
const compressed = libs[0].deflate(rawData);
// Validation // Validation
libs.forEach((Zlib, i) => { libs.forEach((Zlib, i) => {
assert.deepEqual(Zlib.inflate(Zlib.deflate(rawData)), rawData, libPaths[i]); assert.deepEqual(Zlib.deflate(rawData), compressed, `${libPaths[i]} - .deflate()`);
assert.deepEqual(Zlib.inflate(compressed), rawData, `${libPaths[i]} - .inflate()`);
}); });
// Warming up console.log(`raw size: ${rawData.length}bytes`);
console.log(`deflated size: ${compressed.length}bytes`);
console.log(`compression rate: ${(compressed.length / rawData.length * 100).toFixed(1)}%`)
libs.forEach((Zlib, i) => { libs.forEach((Zlib, i) => {
// Warming up
console.time(`Warm - ${libPaths[i]}`); console.time(`Warm - ${libPaths[i]}`);
for (let i = 0; i < 5; i++) { for (let i = 0; i < 10; i++) {
Zlib.deflate(rawData); Zlib.deflate(rawData);
} }
console.timeEnd(`Warm - ${libPaths[i]}`); console.timeEnd(`Warm - ${libPaths[i]}`);
});
// Benchmark // Benchmark
libs.forEach((Zlib, i) => {
console.time(`Benchmark - ${libPaths[i]}`); console.time(`Benchmark - ${libPaths[i]}`);
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
Zlib.deflate(rawData); Zlib.deflate(rawData);
......
...@@ -5,7 +5,7 @@ const fs = require("fs"); ...@@ -5,7 +5,7 @@ const fs = require("fs");
module.exports.initialize = async (wasm_path) => { module.exports.initialize = async (wasm_path) => {
const buff = fs.readFileSync(wasm_path); const buff = fs.readFileSync(wasm_path);
const COMPRESSION_LEVEL = 6; const COMPRESSION_LEVEL = 9;
const NO_ZLIB_HEADER = -1; const NO_ZLIB_HEADER = -1;
const CHUNK_SIZE = 32 * 1024; const CHUNK_SIZE = 32 * 1024;
const map = {}; const map = {};
......
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