Skip to content

Instantly share code, notes, and snippets.

@PARC6502
Created March 5, 2019 16:19
Show Gist options
  • Save PARC6502/b44fa8720c0cf079523e9a6582877d44 to your computer and use it in GitHub Desktop.
Save PARC6502/b44fa8720c0cf079523e9a6582877d44 to your computer and use it in GitHub Desktop.
Performance testing
/* CONCLUSION */
// Surprisingly, for me, the triple loop performed better than the flat loop
/* INITIALISATION */
let xseed = random(10);
let yseed = random(10);
let zseed = random(10);
let step = 50;
let noiseVariance = 0.02;
let sideLength = 200;
for (let x=0;x<sideLength;x+=step) {
for (let y=0;y<sideLength;y+=step) {
for (let z=0;z<sideLength;z+=step) {
let xnoise = xseed + noiseVariance * x;
let ynoise = yseed + noiseVariance * y;
let znoise = zseed + noiseVariance * z;
points.push({
x, y, z, xnoise,ynoise,znoise
})
}
}
}
pointsLength = points.length;
function emptyFunction(x,y,z,noiseFactor) {
//
}
/*TESTING*/
let flatPoints = [];
for (let runs=0;runs<50;runs++) {
let startTime = millis();
for(let i=0;i<pointsLength;i++) {
emptyFunction(points[i].x,points[i].y,points[i].z,noise(points[i].xnoise,points[i].ynoise,points[i].znoise));
}
let totalTime = millis()-startTime;
flatPoints.push(totalTime);
}
console.log(`Flat points, 50 runs: ${flatPoints.reduce( (a,b)=> a+b )}`) // 39.9799999431707
let forgrid = [];
for (let runs=0;runs<50;runs++){
let startTime = millis();
for (let x=0;x<sideLength;x+=step) {
for (let y=0;y<sideLength;y+=step) {
for (let z=0;z<sideLength;z+=step) {
let xnoise = xseed + noiseVariance * x;
let ynoise = yseed + noiseVariance * y;
let znoise = zseed + noiseVariance * z;
emptyFunction(x,y,z,noise(xnoise,ynoise,znoise));
}
}
}
let totalTime = millis()-startTime;
forgrid.push(totalTime);
}
console.log(`For grid, 50 runs: ${forgrid.reduce( (a,b)=> a+b )}`) // 6.684999796561897
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment