Performance testing amp.analyze

edited March 2018 in Share Your Work

Hiya

In case its any use to anyone I thought I'd share some performance testing code and data I made while optimising a music visualizer.

I wondered what impact calling amp.analyze multiple times might have so performed 3 tests to see

test 1 - drawing a 400x400 green screen via loop - average frame rate 18.63485

test 2 - same but call amp.analyze each iteration - average frame rate 8.72345

test 3- pass amp.analyze value into variable once per draw - average frame rate 18.66579

test code:

import processing.sound.*;
Amplitude amp;
SoundFile file;
float analyzed;

void setup() {
  size(400, 400);
  background(255);
  noSmooth();
  file = new SoundFile(this, "Crickets.mp3");
  amp = new Amplitude(this);
  file.play();
  amp.input(file);
}

void draw(){

//test one: just drawing points - average frame rate  18.63485
for ( int iy=0; iy < height; iy++){
    for ( int ix=0; ix < width; ix++){
    stroke(0,255,0);                        
    point(ix, iy);
    }
}  

//test 2: call amp value each iteration - average frame rate 8.72345                                  
//for ( int iy=0; iy < height; iy++){
//    for ( int ix=0; ix < width; ix++){
//        stroke(0,amp.analyze()*200,0); 
//        point(ix, iy);
//    }
//}

//test 3 call amp value once per draw - average frame rate 18.66579
//analyzed = amp.analyze();
//for ( int iy=0; iy < height; iy++){
//    for ( int ix=0; ix < width; ix++){
//        stroke(0,analyzed*200,0);
//        point(ix, iy);
//    }
//}

println(frameRate);

}

Comments

  • Notice that printing in every cycle of draw will affect your test performance. Instead, one of the approaches is to do:

    if(frameCount/120==0) println(framerate);

    Kf

  • thanks for the tip kfrajer, i'll keep that in mind for future testing :)

Sign In or Register to comment.