I'm using 2.0b8 and the first few times a function is called, each time it performs faster than the last time, till it stabilizes on a certain speed. It is the same for both java and android, and depending on the function, it might take anywhere from 2 to 5-6 iterations till the speed stabilizes. Please try this code and see if you get similar results:
- void setup() {
- background(0);
- }
- void draw() {
- }
- void myFunction1() {
- for (int i = 0; i < 50000; i++) {
- float a = random(11);
- float x = cos(sqrt(pow(sin(a), 20)));
- }
- }
- void myFunction2() {
- for (int x = 0; x < 1000; x++) {
- loadPixels();
- for (int i = 0; i < pixels.length; i++) {
- pixels[i] = color(random(255), random(255), random(255));
- }
- updatePixels();
- }
- }
- void keyPressed() {
- if (key == '1') {
- int t = millis();
- myFunction1();
- println(millis()-t);
- }
- if (key == '2') {
- int t = millis();
- myFunction2();
- println(millis()-t);
- }
- }
I'm getting 580, 550, 490, 490, 490,... for myFunction2() everytime I run the program (+/- ~2ms) and 27, 17, 17, 17,... for myFunction1().
Is this natural and has to happen for some reason beyond my knowledge? or is it a bug?
It doesn't really matter if you're gonna loop over a function, but let's say there's a function I wanna run just once during the life time of my program, why does it have to run slower than it "really" can and is there a workaround for this (in case it is not a bug)?
1