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
This test results will probably be skewed by the browser caching image data to GPU memory or elsewhere.
<img
crossorigin="anonymous"
alt=""
src="https://images.unsplash.com/photo-1680925697894-106c453c6e9c"
/>
function getAverageColor(ctx) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var imageData = ctx.getImageData(0, 0, width, height);
var data = imageData.data;
var r = 0;
var g = 0;
var b = 0;
var count = 0;
for (var i = 0, l = data.length; i < l; i += 4) {
r += data[i];
g += data[i+1];
b += data[i+2];
}
count = data.length / 4;
r = ~~(r / count);
g = ~~(g / count);
b = ~~(b / count);
return { r: r, g: g, b: b };
}
// Test could be flawed.
// It looks like browser is good at caching things
// that we draw over and over again onto different
// canvases, some runs will perform in under 1ms
const img = document.getElementsByTagName('img')[0];
Ready to run.
Test | Ops/sec | |
---|---|---|
Resize to 1x1px and read that pixel's color |
| ready |
Resize to 16x16px and calculate arithmetic average |
| ready |
Process image in its natural size and get arithmetic average |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.