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
<canvas id="canvas1" width="500" height="500"></canvas>
<canvas id="canvas2" width="500" height="500"></canvas>
<canvas id="canvas3" width="500" height="500"></canvas>
const c1 = document.querySelector('#canvas1');
const ctx1 = c1.getContext('2d');
ctx1.rect(30, 30, 400, 400);
ctx1.fillStyle = 'red';
ctx1.fill();
const c2 = document.querySelector('#canvas2');
const ctx2 = c2.getContext('2d');
const c3 = document.querySelector('#canvas3');
const gl = c3.getContext('webgl');
const vertexSource = `
attribute vec2 a_position;
uniform vec2 u_resolution;
uniform mat3 u_matrix;
varying vec2 v_texCoord;
void main() {
gl_Position = vec4(u_matrix * vec3(a_position, 1), 1);
v_texCoord = a_position;
}
`
const fragSource = `
precision mediump float;
uniform sampler2D u_image;
varying vec2 v_texCoord;
void main() {
gl_FragColor = texture2D(u_image, v_texCoord);
}
`;
const program = gl.createProgram();
const vertexShader = compileShader(gl, vertexSource, gl.VERTEX_SHADER);
gl.attachShader(program, vertexShader);
const fragShader = compileShader(gl, fragSource, gl.FRAGMENT_SHADER);
gl.attachShader(program, fragShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error(`${gl.getProgramInfoLog(program)}`);
}
const positionLocation = gl.getAttribLocation(program, 'a_position');
matrixLocation = gl.getUniformLocation(program, 'u_matrix');
// const textureLocation = gl.getUniformLocation(program, 'u_image');
gl.useProgram(program);
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
const positions = [
0, 0,
1, 0,
0, 1,
0, 1,
1, 0,
1, 1
];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
function compileShader(gl, source, type) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
return shader;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
No transfer |
| ready |
Transfer image over 2D |
| ready |
Transfer canvas over 2D |
| ready |
Transfer image over WebGL |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.