Skip to content

Instantly share code, notes, and snippets.

@cgcostume
Last active July 23, 2020 15:29
Show Gist options
  • Save cgcostume/f41845db2caf213e4799d1853ad9aefb to your computer and use it in GitHub Desktop.
Save cgcostume/f41845db2caf213e4799d1853ad9aefb to your computer and use it in GitHub Desktop.
benchmark snippet (mostly for webgl-operate)
const benchmark = function() {
/* canvas.frameSize = [320, 240]; */
canvas.controller.multiFrameNumber = 1;
renderer._camera.eye = [Math.sin(0), 1.0, Math.cos(0)];
renderer._camera.center = [0.0, 0.0, 0.0];
canvas.controller.update(true);
const rotations = 4;
const steps = 400;
const warmup = 100;
const step = Math.PI * 2.0 * rotations / (steps + warmup - 1);
var t0 = 0.0;
var t1 = 0.0;
var f0 = 0;
var f1 = 0;
var i = 0;
var subscriber = canvas.controller.frameNumber$.subscribe(function(frameNumber) {
if(frameNumber < canvas.controller.multiFrameNumber) {
return;
}
if(i == 0) {
console.log('---- benchmark warmup ------');
}
if(i == warmup) {
console.log('---- benchmark started -----');
t0 = performance.now();
f0 = canvas.controller.intermediateFrameCount;
}
if(i == steps + warmup) {
t1 = performance.now();
f1 = canvas.controller.intermediateFrameCount;
console.log('---- benchmark finished ----');
console.log('frame size:', canvas.frameSize);
console.log('multiframe number:', canvas.controller.multiFrameNumber);
console.log('steps:', steps);
console.log('intermediate frames:', f1 - f0);
console.log('overall time:', t1 - t0);
console.log('time per frame:', (t1 - t0) / (f1 - f0));
console.log('frames per second:', 1.0 / ((t1 - t0) / (f1 - f0) * 0.001));
subscriber.unsubscribe();
return;
}
renderer._camera.eye = [Math.sin(i * step), 1.0, Math.cos(i * step)];
canvas.controller.update(true);
++i;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment