Verified Commit b0ae1b9b authored by nagayama15's avatar nagayama15

add benchmark script

parent 4991bb69
!Makefile
wasm-flate/
function-reorder/
export-reorder/
operand-swap/
dyn/
/bench-zlib.txt
.PHONY: all
all: \
zlib/function-reorder/ANebjkXMZJwaaRMM \
zlib/export-reorder/ANebjkXMZJwaaRMM \
zlib/operand-swap/ANebjkXMZJwaaRMM \
zlib/function-reorder/Qg5lb3WN8a7eRFRb \
zlib/export-reorder/Qg5lb3WN8a7eRFRb \
zlib/operand-swap/Qg5lb3WN8a7eRFRb \
zlib/function-reorder/oVs8OISLiQH0RXlq \
zlib/export-reorder/oVs8OISLiQH0RXlq \
zlib/operand-swap/oVs8OISLiQH0RXlq
.PHONY: bench-zlib
bench-zlib: \
zlib/raw/wasm-flate \
zlib/function-reorder/ANebjkXMZJwaaRMM \
zlib/export-reorder/ANebjkXMZJwaaRMM \
zlib/operand-swap/ANebjkXMZJwaaRMM \
zlib/function-reorder/Qg5lb3WN8a7eRFRb \
zlib/export-reorder/Qg5lb3WN8a7eRFRb \
zlib/operand-swap/Qg5lb3WN8a7eRFRb \
zlib/function-reorder/oVs8OISLiQH0RXlq \
zlib/export-reorder/oVs8OISLiQH0RXlq \
zlib/operand-swap/oVs8OISLiQH0RXlq
node zlib/raw/bench.js | tee bench-zlib.txt
node zlib/function-reorder/ANebjkXMZJwaaRMM/bench.js | tee -a bench-zlib.txt
node zlib/export-reorder/ANebjkXMZJwaaRMM/bench.js | tee -a bench-zlib.txt
node zlib/operand-swap/ANebjkXMZJwaaRMM/bench.js | tee -a bench-zlib.txt
node zlib/function-reorder/Qg5lb3WN8a7eRFRb/bench.js | tee -a bench-zlib.txt
node zlib/export-reorder/Qg5lb3WN8a7eRFRb/bench.js | tee -a bench-zlib.txt
node zlib/operand-swap/Qg5lb3WN8a7eRFRb/bench.js | tee -a bench-zlib.txt
node zlib/function-reorder/oVs8OISLiQH0RXlq/bench.js | tee -a bench-zlib.txt
node zlib/export-reorder/oVs8OISLiQH0RXlq/bench.js | tee -a bench-zlib.txt
node zlib/operand-swap/oVs8OISLiQH0RXlq/bench.js | tee -a bench-zlib.txt
zlib/raw/wasm-flate: ../node_modules/wasm-flate
cp -r $< $@
# $(eval $(call embed,watermark,method))
define embed
.PHONY: zlib/$2/$1
zlib/$2/$1: zlib/$2/$1/bench.js zlib/$2/$1/wasm-flate/wasm_flate.js zlib/$2/$1/wasm-flate/wasm_flate_bg.wasm
zlib/$2/$1/bench.js: zlib/raw/bench.js
mkdir -p $${@D}
cp $$< $$@
zlib/$2/$1/wasm-flate/wasm_flate.js: zlib/raw/wasm-flate
mkdir -p $${@D}
cp $$</wasm_flate.js $$@
zlib/$2/$1/wasm-flate/wasm_flate_bg.wasm: zlib/raw/wasm-flate
mkdir -p $${@D}
snpi -m $2 -w $1 -o $$@ $$</wasm_flate_bg.wasm
endef
$(eval $(call embed,ANebjkXMZJwaaRMM,function-reorder))
$(eval $(call embed,ANebjkXMZJwaaRMM,export-reorder))
$(eval $(call embed,ANebjkXMZJwaaRMM,operand-swap))
$(eval $(call embed,Qg5lb3WN8a7eRFRb,function-reorder))
$(eval $(call embed,Qg5lb3WN8a7eRFRb,export-reorder))
$(eval $(call embed,Qg5lb3WN8a7eRFRb,operand-swap))
$(eval $(call embed,oVs8OISLiQH0RXlq,function-reorder))
$(eval $(call embed,oVs8OISLiQH0RXlq,export-reorder))
$(eval $(call embed,oVs8OISLiQH0RXlq,operand-swap))
(async function() {
const Crypto = require('crypto');
const assert = require('assert');
const fs = require('fs').promises;
// Generate random bytes
const size = 2_000_000;
const rawData = new Uint8Array(Crypto.randomBytes(size));
// Initialize wasm-flate
globalThis.self = globalThis;
const wasm = await WebAssembly.compile(await fs.readFile(`${__dirname}/wasm-flate/wasm_flate_bg.wasm`));
require(`${__dirname}/wasm-flate/wasm_flate.js`);
const flate = globalThis.wasm_bindgen;
await flate(wasm);
// Check if wasm-flate work properly
const compressed = flate.deflate_encode_raw(rawData);
assert.deepEqual(flate.deflate_decode_raw(compressed), rawData);
// Warm up
flate.deflate_encode_raw(rawData);
flate.deflate_encode_raw(rawData);
flate.deflate_encode_raw(rawData);
const count = 100;
const start = Date.now();
for (let i = 0; i < count; i++) {
flate.deflate_encode_raw(rawData);
}
const end = Date.now();
const duration_ms = end - start;
console.log(`${__dirname}\t${duration_ms / count}`);
})();
This diff is collapsed.
......@@ -15,5 +15,9 @@
"source-map": "^0.7.3",
"vim-wasm": "0.0.13",
"wasm-flate": "^1.0.2-browser"
},
"devDependencies": {
"assert": "^2.0.0",
"crypto": "^1.0.1"
}
}
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