forked from external-repos/squoosh
Write d8 benchmark using the baseline compiler
This commit is contained in:
37
codecs/rotate/benchmark.js
Normal file
37
codecs/rotate/benchmark.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// THIS IS NOT A NODE SCRIPT
|
||||||
|
// This is a d8 script. Please install jsvu[1] and install v8.
|
||||||
|
// Then run `npm run --silent benchmark`.
|
||||||
|
// [1]: https://github.com/GoogleChromeLabs/jsvu
|
||||||
|
async function init() {
|
||||||
|
// Adjustable constants.
|
||||||
|
const imageDimensions = 4096;
|
||||||
|
const iterations = new Array(100);
|
||||||
|
|
||||||
|
// Constants. Don’t change.
|
||||||
|
const imageByteSize = imageDimensions * imageDimensions * 4;
|
||||||
|
const wasmPageSize = 64 * 1024;
|
||||||
|
|
||||||
|
const buffer = readbuffer("rotate.wasm");
|
||||||
|
const {instance} = await WebAssembly.instantiate(buffer);
|
||||||
|
|
||||||
|
const pagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / wasmPageSize);
|
||||||
|
const pagesNeeded = Math.floor((imageByteSize * 2 + 4) / wasmPageSize) + 1;
|
||||||
|
const additionalPagesNeeded = pagesNeeded - pagesAvailable;
|
||||||
|
if(additionalPagesNeeded > 0) {
|
||||||
|
instance.exports.memory.grow(additionalPagesNeeded)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i < 100; i++) {
|
||||||
|
const start = Date.now();
|
||||||
|
instance.exports.rotate(imageDimensions, imageDimensions, 90);
|
||||||
|
iterations[i] = Date.now() - start;
|
||||||
|
}
|
||||||
|
const average = iterations.reduce((sum, c) => sum + c) / iterations.length;
|
||||||
|
const stddev = Math.sqrt(iterations
|
||||||
|
.map(i => Math.pow(i - average, 2))
|
||||||
|
.reduce((sum, c) => sum + c) / iterations.length);
|
||||||
|
print(`n = ${iterations.length}`);
|
||||||
|
print(`Average: ${average}`)
|
||||||
|
print(`StdDev: ${stddev}`);
|
||||||
|
}
|
||||||
|
init().catch(e => console.error(e.stack));
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
"name": "rotate",
|
"name": "rotate",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:image": "docker build -t squoosh-rotate .",
|
"build:image": "docker build -t squoosh-rotate .",
|
||||||
"build": "docker run --rm -v $(pwd):/src squoosh-rotate ./build.sh"
|
"build": "docker run --rm -v $(pwd):/src squoosh-rotate ./build.sh",
|
||||||
|
"benchmark": "v8 --liftoff --no-wasm-tier-up --no-opt ./benchmark.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user