Commit 0d5db91c authored by nagayama15's avatar nagayama15

Add zlib benchmark

parent d909f238
(async function() {
const Zlib = await require('./zlib').initialize('./zlib-sample.wasm');
const rawData = Buffer.from([...Array(10000).keys()]);
const compressedData = Zlib.deflate(rawData);
const uncompressedData = Zlib.inflate(compressedData);
console.log(uncompressedData.equals(rawData));
}());
"use strict"; "use strict";
const fs = require("fs"); const fs = require("fs");
const buff = fs.readFileSync("build/zlib-sample.wasm");
let ret;
module.exports.initialize = async () => { module.exports.initialize = async (wasm_path) => {
if (ret) return ret; const buff = fs.readFileSync(wasm_path);
const COMPRESSION_LEVEL = 6; const COMPRESSION_LEVEL = 6;
const NO_ZLIB_HEADER = -1; const NO_ZLIB_HEADER = -1;
...@@ -62,7 +60,7 @@ module.exports.initialize = async () => { ...@@ -62,7 +60,7 @@ module.exports.initialize = async () => {
} }
getBuffer() { getBuffer() {
return new Buffer(this.buff.buffer, 0, this.offset); return Buffer.from(this.buff.buffer, 0, this.offset);
} }
} }
...@@ -97,11 +95,11 @@ module.exports.initialize = async () => { ...@@ -97,11 +95,11 @@ module.exports.initialize = async () => {
} }
getBuffer() { getBuffer() {
return new Buffer(this.buff.buffer, 0, this.offset); return Buffer.from(this.buff.buffer, 0, this.offset);
} }
} }
ret = { const ret = {
inflate(rawDeflateBuffer) { inflate(rawDeflateBuffer) {
const rawInf = new RawInf(); const rawInf = new RawInf();
for (let offset = 0; offset < rawDeflateBuffer.length; offset += CHUNK_SIZE) { for (let offset = 0; offset < rawDeflateBuffer.length; offset += CHUNK_SIZE) {
......
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