You can use timer1 which can be accurate to a fraction of a microsecond but its easier just doing a big loop of floating points and using millis. If you do a say ten thousand fp operations you should get a pretty good estimate of how long one would take
I used a program to separately calculate ADD and MULT time.
The results were: 12 microseconds and 5 microseconds respectively.
My code has 28 multiplies and 36 sums for a total of 572 microseconds.
In addition it must be considered that I'm working with matrixes and that I'm handling 4 PWM outputs and one analog input.
...Is it enough to exceed 3 milliseconds?
PS:
This is the code I wrote (the printDouble function was created by mem!):
float val = 0.03;
float add = 0.012;
float mult = 1.008;
float time = 0;
int prec = 30000;
long start = 0;
long end = 0;
long total = 0;
void setup() {
digitalWrite(13, HIGH);
}
void loop() {
//ADD
start = millis();
for( int i = 1; i < prec; i++ ) {
val = val + add;
}
end = millis();
total = end - start;
Serial.begin(9600);
Serial.print("It has taken ");
Serial.print( total );
Serial.println(" milliseconds in total.");
time = (total*1000)/prec;
printDouble( time, 6 );
Serial.println(" microseconds per one ADD");
//MULTIPLY
start = millis();
for( int i = 1; i < prec; i++ ) {
val = val*mult;
}
end = millis();
total = end - start;
Serial.begin(9600);
Serial.print("It has taken ");
Serial.print( total );
Serial.println(" milliseconds in total.");
time = (total*1000)/prec;
printDouble( time, 6 );
Serial.println(" microseconds per one MULT");
digitalWrite(13, LOW);
while(1);
}
void printDouble( double val, byte precision){
// prints val with number of decimal places determine by precision
// precision is a number from 0 to 6 indicating the desired decimial places
// example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)
Serial.print (int(val)); //prints the int part
if( precision > 0) {
Serial.print("."); // print the decimal point
unsigned long frac;
unsigned long mult = 1;
byte padding = precision -1;
while(precision--)
mult *=10;
if(val >= 0)
frac = (val - int(val)) * mult;
else
frac = (int(val)- val ) * mult;
unsigned long frac1 = frac;
while( frac1 /= 10 )
padding--;
while( padding--)
Serial.print("0");
Serial.print(frac,DEC) ;
}
}