
* Add sRGB -> RGB conversion before resize * Add clamping for color space conversions * Clip for demultiplication as well * Fixing linear <-> srgb conversion * Update benchmark * Decouple srgb calculations * Generate lookup tables * Update src/codecs/resize/options.tsx * Defaulting on, renaming, removing redundant state
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
// 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
|
||
|
||
self = global = this;
|
||
load("./pkg/resize.js");
|
||
|
||
async function init() {
|
||
// Adjustable constants.
|
||
const inputDimensions = 2000;
|
||
const outputDimensions = 1500;
|
||
const algorithm = 3; // Lanczos
|
||
const iterations = new Array(100);
|
||
|
||
// Constants. Don’t change.
|
||
const imageByteSize = inputDimensions * inputDimensions * 4;
|
||
const imageBuffer = new Uint8ClampedArray(imageByteSize);
|
||
|
||
const module = await WebAssembly.compile(readbuffer("./pkg/resize_bg.wasm"));
|
||
await wasm_bindgen(module);
|
||
[[false, false], [true, false], [false, true], [true, true]].forEach(
|
||
opts => {
|
||
print(`\npremultiplication: ${opts[0]}`);
|
||
print(`color space conversion: ${opts[1]}`);
|
||
print(`==============================`);
|
||
for (let i = 0; i < 100; i++) {
|
||
const start = Date.now();
|
||
wasm_bindgen.resize(
|
||
imageBuffer,
|
||
inputDimensions,
|
||
inputDimensions,
|
||
outputDimensions,
|
||
outputDimensions,
|
||
algorithm,
|
||
...opts
|
||
);
|
||
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, e.stack));
|