Monday September 13, 2010
Hello,
In anticipation of running simple benchmarks on the upcoming Maple IDE-0.0.7 release I began to write simple sketches to "automate" the calculations.
To test math functions I began by timing "empty" loops (which would return a millis() value greater than zero).
Then I added similar loops which either did a simple floating point multiplication or floating point division.
To my surprise, as the size of the compiled code approaches 17000 bytes (the "limit" of sketches uploaded to RAM) stranger things happen.
16184 bytes: the sketch works
16560 bytes: error "serial port already in use"
16616 bytes: error "throbbing LED"
Here is a more detailed summary of my testing.
Restart Maple IDE-0.0.6
Step 1)
compile: 16184 bytes [empty loop, multiplication]
upload: sketch "works"
Step 2): add the second set of multiplication tests
compile: 16560 bytes [empty loop, multiplication, multiplication]
upload: after the IDE prints "Resetting USB to switch back to runtime mode" the Maple IDE reports "Serial port already in use"
Restart Maple IDE-0.0.6
Step 3): restore code to be same as Step 1
compile: 16184 bytes [empty loop, multiplication]
upload: sketch "works"
Step 4): add set of division tests (as expected, the code is slightly larger than Step 2)
compile: 16616 bytes [empty loop, multiplication, division]
upload: after the IDE prints "Resetting USB to switch back to runtime mode" see throbbing LED.
If I upload the code to FLASH memory the first three steps work. However, when FLASH memory is used with the fourth step the IDE stops after the dreaded "Starting download: [" message.
Any ideas?
BTW, I know that printing of floating point values has improved in Arduino 0018 and 0019.
Thanks!
Stephen from NYC
/*
Created 11 September 2010, last updated 13 September 2010
By leaflabs.com forums member "Stephen from NYC"This code is released under a Creative Commons Attribution-Share Alike 3.0 license.
*/
#define LIMIT 30
#define COMM SerialUSB
int totalloops=LIMIT*LIMIT*LIMIT*LIMIT; // four sets of nested loops
int counter1=0;
int counter2=0;
int counter3=0;
int counter4=0;unsigned long empty=0;
unsigned long emptystart=0;
unsigned long emptystop=0;unsigned long floatmultiply=0;
unsigned long floatmultiplystart=0;
unsigned long floatmultiplystop=0;float a= 1.234567890;
float b=10.987654321;
float c=0;float rate=0.0;
void setup()
{
}void loop()
{
COMM.print("\n. . . . . . . . . . . .\n");COMM.println("\nEmpty: Start loops");
emptystart=millis();
for (counter1=0; counter1 < LIMIT; counter1++)
{
for (counter2=0; counter2 < LIMIT; counter2++)
{
for (counter3=0; counter3 < LIMIT; counter3++)
{
for (counter4=0; counter4 < LIMIT; counter4++)
{
// no calculation hereif ((counter1==(LIMIT-1)) && (counter2==(LIMIT-1)) && (counter3==(LIMIT-1)) && (counter4==(LIMIT-1))) COMM.println("Inner loop finished");
}
}
}
}emptystop=millis();
COMM.println("Stop loops");
empty=emptystop-emptystart;
COMM.print("empty: ");
COMM.print(empty);
COMM.println(" milliseconds");// end of "empty" loops / / / / / / / / / / / / /
COMM.println("\nMultiplication 1: Start loops");
floatmultiplystart=millis();
for (counter1=0; counter1 < LIMIT; counter1++)
{
for (counter2=0; counter2 < LIMIT; counter2++)
{
for (counter3=0; counter3 < LIMIT; counter3++)
{
for (counter4=0; counter4 < LIMIT; counter4++)
{
c=a*b;if ((counter1==(LIMIT-1)) && (counter2==(LIMIT-1)) && (counter3==(LIMIT-1)) && (counter4==(LIMIT-1))) COMM.println("Inner loop finished");
}
}
}
}floatmultiplystop=millis();
COMM.println("Stop loops");
floatmultiply=floatmultiplystop-floatmultiplystart;
COMM.print("multiply: ");
COMM.print(floatmultiply-empty);
COMM.print(" milliseconds (for ");
COMM.print(totalloops);
COMM.println(" loops)");COMM.print("float multiplication rate: ");
rate=(floatmultiply-empty) * 1000 / totalloops;
COMM.print(rate);
COMM.println(" microseconds per multiplication");
// end of first multiplication / / / / / / / / / / / / /
/*
COMM.println("\nMultiplication 2: Start loops");
floatmultiplystart=millis();
for (counter1=0; counter1 < LIMIT; counter1++)
{
for (counter2=0; counter2 < LIMIT; counter2++)
{
for (counter3=0; counter3 < LIMIT; counter3++)
{
for (counter4=0; counter4 < LIMIT; counter4++)
{
c=a*b;if ((counter1==(LIMIT-1)) && (counter2==(LIMIT-1)) && (counter3==(LIMIT-1)) && (counter4==(LIMIT-1))) COMM.println("Inner loop finished");
}
}
}
}floatmultiplystop=millis();
COMM.println("Stop loops");
floatmultiply=floatmultiplystop-floatmultiplystart;
COMM.print("multiply: ");
COMM.print(floatmultiply-empty);
COMM.print(" milliseconds (for ");
COMM.print(totalloops);
COMM.println(" loops)");COMM.print("float multiplication rate: ");
rate=(floatmultiply-empty) * 1000 / totalloops;
COMM.print(rate);
COMM.println(" microseconds per multiplication");
*/
// end of second multiplication / / / / / / / / / / / / /
/*
// division
COMM.println("\nDivision: Start loops");
floatmultiplystart=millis();
for (counter1=0; counter1 < LIMIT; counter1++)
{
for (counter2=0; counter2 < LIMIT; counter2++)
{
for (counter3=0; counter3 < LIMIT; counter3++)
{
for (counter4=0; counter4 < LIMIT; counter4++)
{
c=a/b;if ((counter1==(LIMIT-1)) && (counter2==(LIMIT-1)) && (counter3==(LIMIT-1)) && (counter4==(LIMIT-1))) COMM.println("Inner loop finished");
}
}
}
}floatmultiplystop=millis();
COMM.println("Stop loops");
floatmultiply=floatmultiplystop-floatmultiplystart;
COMM.print("division: ");
COMM.print(floatmultiply-empty);
COMM.print(" milliseconds (for ");
COMM.print(totalloops);
COMM.println(" loops)");COMM.print("float diviion rate: ");
rate=(floatmultiply-empty) * 1000 / totalloops;
COMM.print(rate);
COMM.println(" microseconds per division");
*/
}