What is a reliable way to benchmark a device?

I’m trying to find a way to benchmark a device before drawing a scene so that I can select the appropriate shaders to use. I’ve tested drawing some boxes with MeshStandardMaterial in a render target and measuring how long it takes but the times are not consistent. Sometimes it renders 10x faster on the same device.

Is there something I can render that would give a more consistent performance test? Or is there another way of profiling the performance levels of different devices? Ideally something that doesn’t cause a performance problem before I render the scene.

Perhaps there’s a shader that can test the raw compute performance of a GPU?

Related:

The first answer really sums it up quite well.

Is it reliable to do the following:

time1 = performance.now();
renderer.render(scene, camera);
time2 = performance.now()
result = time2 - time1;

Even when I slow down the rendering a lot, the timing seems to finish faster than it takes to draw. The GPU and the CPU processes are separate and while one will hold up the other, it seems like I should be using a method of timing the render from the GPU context.

The frame is produced when WebGLRenderer.render() returns so it is valid to measure like this.

1 Like

I tried putting a long loop in a fragment shader on an object by overriding the shader using material.onBeforeCompile.

for(int loop = 0; loop < 10000000; loop++) {}

If I make that loop long it takes a long time to draw but the time returned for the render call seems to be independent of this.

After testing a few setups, drawing a lot of simple shapes to a render target seems to give consistent values. I tried using a finish call after the scene render to block the Javascript until the WebGL rendering was done but I’m not sure it made much difference:

Drawing around 1000 cubes in a flat fixed pattern to a render texture before setting up a scene gives a reasonably consistent render time. Then I choose a threshold for the performance and if anything is below it, switch some of the shaders. On slow devices, drawing that many shapes takes about 1.5s to render but it’s worth it to be able to improve the performance of the main scene and the optimization happens before the scene displays.

1 Like