Verified Commit 61c870c6 authored by nagayama15's avatar nagayama15

Change output of watermarked wasm binary

parent 43e4b627
...@@ -7,48 +7,54 @@ W3 := 0d97880d ...@@ -7,48 +7,54 @@ W3 := 0d97880d
W4 := fe8191b3 W4 := fe8191b3
all: \ all: \
ammo-1-${W1} ammo-2-${W1} ammo-3-${W1} \ dist/ammo-1-${W1} dist/ammo-2-${W1} dist/ammo-3-${W1} \
ammo-1-${W2} ammo-2-${W2} ammo-3-${W2} \ dist/ammo-1-${W2} dist/ammo-2-${W2} dist/ammo-3-${W2} \
ammo-1-${W3} ammo-2-${W3} ammo-3-${W3} \ dist/ammo-1-${W3} dist/ammo-2-${W3} dist/ammo-3-${W3} \
ammo-1-${W4} ammo-2-${W4} ammo-3-${W4} \ dist/ammo-1-${W4} dist/ammo-2-${W4} dist/ammo-3-${W4} \
# #
ammo-1-${W1}: ammo-1-${W1}/ammo.wasm.js ammo-1-${W1}/ammo.wasm.wasm test: all
ammo-1-${W2}: ammo-1-${W2}/ammo.wasm.js ammo-1-${W2}/ammo.wasm.wasm node test.js
ammo-1-${W3}: ammo-1-${W3}/ammo.wasm.js ammo-1-${W3}/ammo.wasm.wasm
ammo-1-${W4}: ammo-1-${W4}/ammo.wasm.js ammo-1-${W4}/ammo.wasm.wasm bench: all
ammo-2-${W1}: ammo-2-${W1}/ammo.wasm.js ammo-2-${W1}/ammo.wasm.wasm node benchmark.js
ammo-2-${W2}: ammo-2-${W2}/ammo.wasm.js ammo-2-${W2}/ammo.wasm.wasm
ammo-2-${W3}: ammo-2-${W3}/ammo.wasm.js ammo-2-${W3}/ammo.wasm.wasm dist/ammo-1-${W1}: dist/ammo-1-${W1}/ammo.wasm.js dist/ammo-1-${W1}/ammo.wasm.wasm
ammo-2-${W4}: ammo-2-${W4}/ammo.wasm.js ammo-2-${W4}/ammo.wasm.wasm dist/ammo-1-${W2}: dist/ammo-1-${W2}/ammo.wasm.js dist/ammo-1-${W2}/ammo.wasm.wasm
ammo-3-${W1}: ammo-3-${W1}/ammo.wasm.js ammo-3-${W1}/ammo.wasm.wasm dist/ammo-1-${W3}: dist/ammo-1-${W3}/ammo.wasm.js dist/ammo-1-${W3}/ammo.wasm.wasm
ammo-3-${W2}: ammo-3-${W2}/ammo.wasm.js ammo-3-${W2}/ammo.wasm.wasm dist/ammo-1-${W4}: dist/ammo-1-${W4}/ammo.wasm.js dist/ammo-1-${W4}/ammo.wasm.wasm
ammo-3-${W3}: ammo-3-${W3}/ammo.wasm.js ammo-3-${W3}/ammo.wasm.wasm dist/ammo-2-${W1}: dist/ammo-2-${W1}/ammo.wasm.js dist/ammo-2-${W1}/ammo.wasm.wasm
ammo-3-${W4}: ammo-3-${W4}/ammo.wasm.js ammo-3-${W4}/ammo.wasm.wasm dist/ammo-2-${W2}: dist/ammo-2-${W2}/ammo.wasm.js dist/ammo-2-${W2}/ammo.wasm.wasm
dist/ammo-2-${W3}: dist/ammo-2-${W3}/ammo.wasm.js dist/ammo-2-${W3}/ammo.wasm.wasm
ammo-%/ammo.wasm.js: ammo.js/builds/ammo.wasm.js dist/ammo-2-${W4}: dist/ammo-2-${W4}/ammo.wasm.js dist/ammo-2-${W4}/ammo.wasm.wasm
dist/ammo-3-${W1}: dist/ammo-3-${W1}/ammo.wasm.js dist/ammo-3-${W1}/ammo.wasm.wasm
dist/ammo-3-${W2}: dist/ammo-3-${W2}/ammo.wasm.js dist/ammo-3-${W2}/ammo.wasm.wasm
dist/ammo-3-${W3}: dist/ammo-3-${W3}/ammo.wasm.js dist/ammo-3-${W3}/ammo.wasm.wasm
dist/ammo-3-${W4}: dist/ammo-3-${W4}/ammo.wasm.js dist/ammo-3-${W4}/ammo.wasm.wasm
dist/ammo-%/ammo.wasm.js: ammo.js/builds/ammo.wasm.js
@mkdir -p ${@D} @mkdir -p ${@D}
cp $< $@ cp $< $@
ammo-1-%/ammo.wasm.wasm: ammo.js/builds/ammo.wasm.wasm dist/ammo-1-%/ammo.wasm.wasm: ammo.js/builds/ammo.wasm.wasm
@mkdir -p ${@D} @mkdir -p ${@D}
${SNPI} $< funcord ${@:zlib-1-%.wasm=%} > ${@:%.wasm=%.wast} ${SNPI} $< funcord ${@:zlib-1-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
ammo-2-%/ammo.wasm.wasm: ammo.js/builds/ammo.wasm.wasm dist/ammo-2-%/ammo.wasm.wasm: ammo.js/builds/ammo.wasm.wasm
@mkdir -p ${@D} @mkdir -p ${@D}
${SNPI} $< opswap ${@:zlib-2-%.wasm=%} > ${@:%.wasm=%.wast} ${SNPI} $< opswap ${@:zlib-2-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
ammo-3-%/ammo.wasm.wasm: ammo-1-%/ammo.wasm.wasm dist/ammo-3-%/ammo.wasm.wasm: dist/ammo-1-%/ammo.wasm.wasm
@mkdir -p ${@D} @mkdir -p ${@D}
${SNPI} $< opswap ${@:zlib-3-%.wasm=%} > ${@:%.wasm=%.wast} ${SNPI} $< opswap ${@:zlib-3-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
clean: clean:
${RM} -rf ammo-* ${RM} -rf dist
.PHONY: all clean .PHONY: all test bench clean
...@@ -19,18 +19,18 @@ const stress = require("./stress"); ...@@ -19,18 +19,18 @@ const stress = require("./stress");
const wasms = [ const wasms = [
"ammo.js/builds", "ammo.js/builds",
"ammo-1-0c9c85c7", "dist/ammo-1-0c9c85c7",
"ammo-1-0d97880d", "dist/ammo-1-0d97880d",
"ammo-1-60b725f1", "dist/ammo-1-60b725f1",
"ammo-1-fe8191b3", "dist/ammo-1-fe8191b3",
"ammo-2-0c9c85c7", "dist/ammo-2-0c9c85c7",
"ammo-2-0d97880d", "dist/ammo-2-0d97880d",
"ammo-2-60b725f1", "dist/ammo-2-60b725f1",
"ammo-2-fe8191b3", "dist/ammo-2-fe8191b3",
"ammo-3-0c9c85c7", "dist/ammo-3-0c9c85c7",
"ammo-3-0d97880d", "dist/ammo-3-0d97880d",
"ammo-3-60b725f1", "dist/ammo-3-60b725f1",
"ammo-3-fe8191b3" "dist/ammo-3-fe8191b3"
]; ];
for (wasm of wasms) { for (wasm of wasms) {
......
zlib-1-*.wasm dist/
zlib-2-*.wasm
zlib-3-*.wasm
*.wast
...@@ -9,36 +9,43 @@ W4 := fe8191b3 ...@@ -9,36 +9,43 @@ W4 := fe8191b3
SRC := zlib-sample.wasm SRC := zlib-sample.wasm
TARGETS := \ TARGETS := \
zlib-1-${W1}.wasm \ dist/zlib-1-${W1}.wasm \
zlib-2-${W1}.wasm \ dist/zlib-2-${W1}.wasm \
zlib-3-${W1}.wasm \ dist/zlib-3-${W1}.wasm \
zlib-1-${W2}.wasm \ dist/zlib-1-${W2}.wasm \
zlib-2-${W2}.wasm \ dist/zlib-2-${W2}.wasm \
zlib-3-${W2}.wasm \ dist/zlib-3-${W2}.wasm \
zlib-1-${W3}.wasm \ dist/zlib-1-${W3}.wasm \
zlib-2-${W3}.wasm \ dist/zlib-2-${W3}.wasm \
zlib-3-${W3}.wasm \ dist/zlib-3-${W3}.wasm \
zlib-1-${W4}.wasm \ dist/zlib-1-${W4}.wasm \
zlib-2-${W4}.wasm \ dist/zlib-2-${W4}.wasm \
zlib-3-${W4}.wasm dist/zlib-3-${W4}.wasm
all: ${TARGETS} all: ${TARGETS}
bench: all
node benchmark.js node benchmark.js
zlib-1-%.wasm: zlib-sample.wasm dist/zlib-1-%.wasm: zlib-sample.wasm
${SNPI} $< funcord ${@:zlib-1-%.wasm=%} > ${@:%.wasm=%.wast} @mkdir -p ${@D}
${SNPI} $< funcord ${@:dist/zlib-1-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
zlib-2-%.wasm: zlib-sample.wasm dist/zlib-2-%.wasm: zlib-sample.wasm
${SNPI} $< opswap ${@:zlib-2-%.wasm=%} > ${@:%.wasm=%.wast} @mkdir -p ${@D}
${SNPI} $< opswap ${@:dist/zlib-2-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
zlib-3-%.wasm: zlib-1-%.wasm dist/zlib-3-%.wasm: dist/zlib-1-%.wasm
${SNPI} $< opswap ${@:zlib-3-%.wasm=%} > ${@:%.wasm=%.wast} @mkdir -p ${@D}
${SNPI} $< opswap ${@:dist/zlib-3-%.wasm=%} > ${@:%.wasm=%.wast}
${AS} ${@:%.wasm=%.wast} -o $@ ${AS} ${@:%.wasm=%.wast} -o $@
${RM} ${@:%.wasm=%.wast} ${RM} ${@:%.wasm=%.wast}
clean: clean:
${RM} zlib-1-*.wasm zlib-2-*.wasm zlib-3-*.wasm *.wast ${RM} dist
.PHONY: all bench clean
const Crypto = require('crypto'); const Crypto = require("crypto");
const assert = require('assert'); const assert = require("assert");
const size = 1_000_000; const size = 1_000_000;
const rawData = Crypto.randomBytes(size); const rawData = Crypto.randomBytes(size);
(async function () { (async function() {
const libPaths = [ const libPaths = [
`zlib-sample.wasm`, `zlib-sample.wasm`,
'zlib-1-0c9c85c7.wasm', "dist/zlib-1-0c9c85c7.wasm",
'zlib-1-0d97880d.wasm', "dist/zlib-1-0d97880d.wasm",
'zlib-1-60b725f1.wasm', "dist/zlib-1-60b725f1.wasm",
'zlib-1-fe8191b3.wasm', "dist/zlib-1-fe8191b3.wasm",
'zlib-2-0c9c85c7.wasm', "dist/zlib-2-0c9c85c7.wasm",
'zlib-2-0d97880d.wasm', "dist/zlib-2-0d97880d.wasm",
'zlib-2-60b725f1.wasm', "dist/zlib-2-60b725f1.wasm",
'zlib-2-fe8191b3.wasm', "dist/zlib-2-fe8191b3.wasm",
'zlib-3-0c9c85c7.wasm', "dist/zlib-3-0c9c85c7.wasm",
'zlib-3-0d97880d.wasm', "dist/zlib-3-0d97880d.wasm",
'zlib-3-60b725f1.wasm', "dist/zlib-3-60b725f1.wasm",
'zlib-3-fe8191b3.wasm', "dist/zlib-3-fe8191b3.wasm"
]; ];
const libs = await Promise.all(libPaths.map(async path => await require('./zlib').initialize(`${__dirname}/${path}`))); const libs = await Promise.all(
libPaths.map(
async path => await require("./zlib").initialize(`${__dirname}/${path}`)
)
);
const compressed = libs[0].deflate(rawData); const compressed = libs[0].deflate(rawData);
// Validation // Validation
libs.forEach((Zlib, i) => { libs.forEach((Zlib, i) => {
assert.deepEqual(Zlib.deflate(rawData), compressed, `${libPaths[i]} - .deflate()`); assert.deepEqual(
assert.deepEqual(Zlib.inflate(compressed), rawData, `${libPaths[i]} - .inflate()`); Zlib.deflate(rawData),
compressed,
`${libPaths[i]} - .deflate()`
);
assert.deepEqual(
Zlib.inflate(compressed),
rawData,
`${libPaths[i]} - .inflate()`
);
}); });
const compressionRate = compressed.length / rawData.length;
console.log(`raw size: ${rawData.length}bytes`); console.log(`raw size: ${rawData.length}bytes`);
console.log(`deflated size: ${compressed.length}bytes`); console.log(`deflated size: ${compressed.length}bytes`);
console.log(`compression rate: ${(compressed.length / rawData.length * 100).toFixed(1)}%`) console.log(`compression rate: ${(compressionRate * 100).toFixed(1)}%`);
libs.forEach((Zlib, i) => { libs.forEach((Zlib, i) => {
// Warming up // Warming up
...@@ -50,5 +64,4 @@ const rawData = Crypto.randomBytes(size); ...@@ -50,5 +64,4 @@ const rawData = Crypto.randomBytes(size);
} }
console.timeEnd(`Benchmark - ${libPaths[i]}`); 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