jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Tests different methods of manipulating pixels using the canvas.
<canvas id="canvas" height="256" width="256"></canvas>
//precompute everything to only test raw pixel pushing performance
var canvas = document.getElementById('canvas'),
canvasWidth = canvas.width,
canvasHeight = canvas.height,
ctx = canvas.getContext('2d'),
imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight),
data = imageData.data,
buf = new ArrayBuffer(data.length),
buf8 = new Uint8ClampedArray(buf),
data32 = new Uint32Array(buf),
pixelsI32 = new Int32Array(data.buffer),
pixelsU32 = new Uint32Array(data.buffer),
view = new DataView(data.buffer),
temp = ctx.createImageData(canvasWidth, canvasHeight),
tempData = temp.data,
px = ctx.createImageData(1, 1),
pxData = px.data,
r = [],
g = [],
b = [],
a = [],
hex = [],
rgb = [],
rgba = [],
b32 = [],
v32 = [];
ctx.globalAlpha = 1;
for (var y = 0; y < canvasHeight; y++) {
for (var x = 0; x < canvasWidth; x++) {
var red = x * y & 0xff,
green = x & 0xff,
blue = y & 0xff,
alpha = 255;
r.push(red);
g.push(green);
b.push(blue);
a.push(alpha);
rgb.push('rgb(' + red + ',' + green + ',' + blue + ')');
rgba.push('rgba(' + red + ',' + green + ',' + blue + ',' + (alpha / 255) + ')');
hex.push("#" + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1));
b32.push((alpha << 24) | (blue << 16) | (green << 8) | red);
v32.push((red << 24) | (green << 16) | (blue << 8) | alpha);
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
putImageData |
| ready |
putImageData Direct |
| ready |
putImageData Temp |
| ready |
putImageData 1PX |
| ready |
32-bit |
| ready |
32-bit Direct |
| ready |
32-bit Uint |
| ready |
32-bit DataView |
| ready |
fillRect RGBA |
| ready |
fillRect RGB |
| ready |
fillRect HEX |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.