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
function sizeimage_max(canvasWidth, canvasHeight, imageAspect)
{
var canvasAspect = canvasWidth / canvasHeight;
var xpos = 0, ypos = 0;
var sizex, sizey;
if (canvasAspect < imageAspect) {
sizey = canvasHeight;
sizex = canvasHeight * imageAspect;
xpos = (canvasWidth-sizex)/2;
} else {
sizex = canvasWidth;
sizey = canvasWidth / imageAspect;
ypos = (canvasHeight -sizey)/2;
}
//final image position and size
return [xpos, ypos, sizex, sizey];
}
function sizeimage_candidate(canvasWidth, canvasHeight, imageAspect)
{
let xpos = 0, ypos = 0, sizex = 0, sizey = 0;
// console.log('Input:', canvasWidth, canvasHeight, imageAspect);
let height = canvasHeight,
width = canvasWidth,
aspect = width / height;
// console.log(aspect);
if (aspect !== imageAspect) {
let x = imageAspect / aspect;
if (x > 1) {
width = Math.floor(width * x);
} else {
height = Math.floor(height / x);
}
aspect = width / height;
// console.log(x, width, height, aspect);
}
sizex = width;
if (width > canvasWidth) {
xpos -= Math.floor((width - canvasWidth) / 2);
}
sizey = height;
if (height > canvasHeight) {
ypos -= Math.floor((height - canvasHeight) / 2);
}
//final image position and size
return [xpos, ypos, sizex, sizey];
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Max |
| ready |
candidate |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.