xxxxxxxxxx
var t=0,n=1;
function setup() {
createCanvas(windowWidth,windowHeight, WEBGL);
noStroke();
fill(0,70,160);
}
function draw() {
t+=0.0005;
background(0,0,0);
for(let i=0; i<120; i++) {
if(!mouseIsPressed) n = Math.floor(random()*50); else n = random()*50;
//rect(80,0, 120+50*n,2); //264ms/60iter
quad(80,0, 200+n,0, 200+n,4, 80,2); //266ms/60iter 640ms/240iter
rotate(TAU/120);
}
}
/*
anomaly in WEBGL only
850ms scripting time without random() during 5005ms duration
4831ms scripting time with random() during 5005ms duration
this extra function call causes quad() to execute longer
with higher frequency of "Minor GC" occuring in jsheap on every frame
29.5-67.5 MB vs 27.9-34.9 MB
_main.default.RenderGL.quad completes in 2.15ms vs 15.11ms
Could it be due to the size of the quad varying?
When the quad is the same size, perhaps an optimization occurs which re-uses the space
whereas, when the quad size varies, perhaps that optimization cannot help, therefore more space/time is required?
turns out that the call to noise() or random() returned a float which causes quad() to take longer
when the return value is converted to an int using floor(), then quad() behaves well
another measurement of 4999ms
4641ms when not floored
212ms when floored
*/