Go Down

Topic: Speed of floating point operations -- test results (Read 9 times) previous topic - next topic

jmknapp

Apr 07, 2008, 07:57 pm Last Edit: Apr 07, 2008, 07:58 pm by jmknapp Reason: 1
Was curious as to the speed of floating point operations on the 16MHz Arduino Diecimila. Could only find a few threads about that (e.g., http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206534749), with no answer, so I ran some tests. Here's a graph of results comparing the speed of a multiply operation using the various data types:



The way the C test program was set up, the values above include the time for the multiply operation as well as one memory read and one memory write.

These are the lengths of the data types in bytes:

byte 1
int 2
long int 4
double 4

I also looked at the time to do a sin() call to the math library: 255 microseconds!

Anyway, based on these results, looks like the Diecimila is about a 0.1 megaflop device, using 4-byte floats/doubles.

follower

Quote
These are the lengths of the data types in bytes:

byte 1
int 2
long int 4
double 4

...

Anyway, based on these results, looks like the Diecimila is about a 0.1 megaflop device, using 4-byte floats/doubles.

I'm too lazy to check for myself, but won't a float be 4 bytes and a double be 8 bytes? (Referring to: http://www.cppreference.com/data_types.html)

--Phil.

jmknapp

Quote
I'm too lazy to check for myself, but won't a float be 4 bytes and a double be 8 bytes? (Referring to: http://www.cppreference.com/data_types.html)


Not for the Arduino--sizeof(float) and sizeof(double) both return 4. As your link states: "The size and range of any data type is compiler and architecture dependent."

Joe

Oracle

Quote
Was curious as to the speed of floating point operations on the 16MHz Arduino Diecimila. Could only find a few threads about that (e.g., http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206534749), with no answer, so I ran some tests.


As the person who started the other thread thank you for that.

I must say I'm surprised it can do doubles so fast.  Do you have data for division?  With division algorithms, you'll need to test a wide range of denominators to get a good feel.

BTW, double is supposed to be 8-bytes: http://www.arduino.cc/en/Reference/Double
I don't know why sizeof() would return 4.

jmknapp

#4
Apr 09, 2008, 12:42 pm Last Edit: Apr 09, 2008, 12:46 pm by jmknapp Reason: 1
Quote

I must say I'm surprised it can do doubles so fast.  Do you have data for division?  With division algorithms, you'll need to test a wide range of denominators to get a good feel.


I just tried it with several different denominators & always get a result in the range of 34 microseconds. So floating point division is about 3-4 times slower than multiplication (9 usec).

Even so, that's about 30,000 divisions per second. This seems fast enough for (much) government work!  ::)

Quote

BTW, double is supposed to be 8-bytes: http://www.arduino.cc/en/Reference/Double
I don't know why sizeof() would return 4.


I would tend to believe what the compiler is reporting, but I just posted something on this in Bugs/Suggestions, so we will see.

Oracle

Quote

I just tried it with several different denominators & always get a result in the range of 34 microseconds. So floating point division is about 3-4 times slower than multiplication (9 usec).

Even so, that's about 30,000 divisions per second. This seems fast enough for (much) government work!  ::)


Hey, I work for the government  ;)

34 microseconds is amazing.  I originally tried to do my current project on a pic16F, and was getting results about a thousand times slower.  It was at the point where I was trying to use 2 PICs, one basically as a floating-point processor, and the whole project got kludgy.  Not to mention all the fun I had learning how to do floating point division in assembly on a processor that only does 8-bit integer add and subtract.

Because of the speed, it just works on the Ardunio.  And the HLL is so much faster than messing around with assembly or JAL.  What took me weeks on the PIC took an hour on the Arduino.

Quote

I would tend to believe what the compiler is reporting, but I just posted something on this in Bugs/Suggestions, so we will see.


I saw your post there, I'm looking forward to seeing the answer.  If we trust the compiler, there's no difference beween float and double though.  Float is good enough for my purposes though.

mellis

Yep, on the AVR's, float and double are both 32 bits.

jmknapp

Quote
Yep, on the AVR's, float and double are both 32 bits.


Thanks for checking it out & changing the docs.

Oracle

Quote
Yep, on the AVR's, float and double are both 32 bits.


So are floats and doubles identical?

nkcelectronics

Confirmed, in winavr float == double (source: "WinAVR / gccavr does not support doubles, in other words: double is considered as float" in http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_Float) and also from the maintainer of avr-libc: http://www.avrfreaks.net/index.php?module=PNphpBB2&file=viewtopic&t=50770&highlight=

mem

#10
Apr 11, 2008, 09:47 am Last Edit: Apr 11, 2008, 09:50 am by mem Reason: 1
and for most Arduino apps floats are more than sufficient

Oracle

Quote
and for most Arduino apps floats are more than sufficient


So far, I haven't hit a situation where I absolutely had to have a double in an embedded project, but why does that statement make me think "640k ought to be enough for anyone"?

mem

#12
Apr 11, 2008, 04:47 pm Last Edit: Apr 11, 2008, 04:48 pm by mem Reason: 1
Quote
Quote
and for most Arduino apps floats are more than sufficient


So far, I haven't hit a situation where I absolutely had to have a double in an embedded project, but why does that statement make me think "640k ought to be enough for anyone"?

And you say that in the forum about the highly capable Arduino that has just 1k  ;)

Oracle

#13
Apr 11, 2008, 05:37 pm Last Edit: Apr 11, 2008, 05:39 pm by Oracle Reason: 1
Quote
So far, I haven't hit a situation where I absolutely had to have a double in an embedded project, but why does that statement make me think "640k ought to be enough for anyone"?
Quote
And you say that in the forum about the highly capable Arduino that has just 1k  ;)


If you need more memory than you can count in bytes, your runtime code is too sloppy.  (please don't quote me on that ;) ).

-- and to clarify, I mean code, not data.

Go Up