Teensy LC vs. Teensy 2.0 Floating Point

Status
Not open for further replies.
Neither has floating point in hardware as do many ARM Cortex M4s. Both LC and Teensy 2.0 (8 bit AVR) use software libraries for floating point.

But the LC, being a 32 bit architecture, will be much faster.
 
None of the Teensies have floating point in hardware (although a few ARM Cortex M4s do). 3.0, 3.1, LC and Teensy 2.0/+2.0 (8 bit AVR) use software libraries for floating point.

Having corrected your statement, it still seems to have no bearing on the original question?
 
In a floating point calculation war, which board would win?

My guess is you care only about speed.

But if accuracy matters, consider the 8 bit AVR boards only support single precision. When you use "double", AVR boards implement the same 32 bit number as "float". The ARM boards do implement 64 bit double precision. Obviously that's much slower, and on Teensy-LC and Teensy 3.1 you need to be careful to use 32 bit single precision (lots of stuff defaults to double precision) if you want speed. But if accuracy matters, you simply can't get 64 bit floats on Teensy 2.0.

As far as speed is concerned, I wrote a very quick and not necessarily great benchmark, just now, just for you. Well, and also for my own curiosity.

Code:
void setup() {
  Serial.begin(115200);
}

void loop() {
  float x, y, z;
  unsigned long t1, t2;
  int n = Serial.parseInt();
  // returns n = 0 after short timeout... but the compiler
  // does not "know" the value of n, so we can use it for
  // math without the compiler optimizing things away
  t1 = micros();
  x = n + 5.234f;
  y = sinf(x);
  z = x / 0.12f + y;
  t2 = micros();
  Serial.print("result = ");
  Serial.println(z);
  Serial.print("usec = ");
  Serial.println(t2 - t1);
}

I ran it just now on the 3 boards, at default settings. These results are the number of microseconds, so smaller numbers are better.

Code:
Teensy 3.1   34
Teensy-LC    111
Teensy 2.0   164
 
None of the Teensies have floating point in hardware (although a few ARM Cortex M4s do). 3.0, 3.1, LC and Teensy 2.0/+2.0 (8 bit AVR) use software libraries for floating point.
my statement is correct. Some ARM Cortex M4s have hardware floating point.
Freescale's K2x line includes some with floating point, though as said, none of the K20's in the Teensy 3.x so far.
 
Last edited:
Actually Steve, your point about the 32 bit architecture necessarily being "much faster" is debatable.

With the benchmark I just posted, certainly Teensy 3.1 with Cortex-M4 is much faster. But Cortex-M0+ hardly seems much faster. Both are running at a much higher clock speed than AVR. If you normalize by clock rates, the 32 bit ARM numbers aren't nearly as impressive!

If anything, I think this really shows how impressively optimized the avr-libc float functions are.

However, accuracy should also be considered. I'm pretty sure the float routines in newlib for ARM give exactly the right results. Having looked at the avr-libc source code a few times, I would not be surprised if it's cutting a few corners and making minor compromises on accuracy, even for single precision (particularly in the trig functions).

For the best, or at least acceptable performance for the minimum possible cost, Cortex-M0+ looks very good!
 
.. all I know is that happily these little gems can do floating point calculations faster than I can. ;)
 
Status
Not open for further replies.
Back
Top