Code optimization using FOR loops & point(x,y,z)
in
Programming Questions
•
3 years ago
Are there techniques to optimize a triple FOR loop with high dimensions?
Since the number of times the code is run increases exponentially, it gets slow real fast!
This does not make my frameRate happy
Here is some test code and the respective frameRates I got with it...
Since the number of times the code is run increases exponentially, it gets slow real fast!
This does not make my frameRate happy
Here is some test code and the respective frameRates I got with it...
- import processing.opengl.*;
- int dimensions = 50;
- // dimensions 10 = frameRate 1000+
- // dimensions 20 = frameRate 400
- // dimensions 30 = frameRate 130
- // dimensions 40 = frameRate 55
- // dimensions 50 = frameRate 29
- // dimensions 60 = frameRate 17
- // dimensions 70 = frameRate 11
- // dimensions 80 = frameRate 7
- // dimensions 90 = frameRate 5
- // dimensions 600 = frameRate :-(
- void setup(){
- size(500,500,OPENGL);
- frameRate(1000);
- }
- void draw() {
- background(255,255,255);
- translate(width/2-dimensions/2,height/2-dimensions/2,300);
- for (int x=0; x<dimensions; x++) {
- for (int y=0; y<dimensions; y++) {
- for (int z=0; z<dimensions; z++) {
- stroke(x,y,z);
- point(x,y,z);
- }
- }
- }
- println("Frame: " + frameCount + " || FrameRate : " + frameRate);
- }
1