Arduino Zero running slower than my Arduino micro!

I have a sketch that interpolates points from polynomial equations. I’ve benchmarked the timing using a micros() timestamp before and after the calculations and have found that the loop iterations are actually shorter (sometimes as much as half as long on my arduino micro than on my brand-new arduino zero? How can that be, with such a faster processor on the zero?

pump-engine_simulator.ino (5.19 KB)

no idea but

to speed up the polynome-math

y = pow(capacity,2)
=>
y = capacity * capacity

y = pow(x, 4)
==>
x2 = x * x;
y = x2 * x2;

in fact Horners rule is for faster polynome math

poly=(A1pow(capacity,2)+A2capacity+A3);
==>
poly = (A1 * capacity + A2) * capacity + A3;

can be applied for al the polynomes including higher grades


speed up float compares by removing unneeded ones. CHeck it.

 float restingV(float capacity){
    float resting;
    if (capacity <= 0.0156)  
      { resting = polynomialA(capacity); Serial.print("A,"); }
    else if (capacity <= .4164) 
      { resting = polynomialB(capacity); Serial.print("B,"); }
    else if (capacity <= 9.9948) 
      { resting = polynomialC(capacity); Serial.print("C,"); }
    else { resting = polynomialD(capacity); Serial.print("D,"); }
   return resting;     
 }

That's not TOO surprising.

The zero will do double (64bit) floating point math unless you're careful, and it does NOT have an optimized floating point library for the CM0 (a limitation of arm-gcc, currently.) The AVR will do 32bit floating point math (even if you specify "double"), and is very highly optimized.

Replace all your "doubles" with "float" and be sure to use the single-precision version of all the functions (powf() instead of pow() for example), do get apples to apples comparisons.

I've been playing with an alternative float library: http://www.quinapalus.com/qfplib.html, which is pretty cool. In addition to being faster, it's very TINY compared to the default gcc software float routines (which is what Zero will normally run.)

(Note that Due, having a CM3 cpu rather than a CM0, DOES have optimized software floating point.)