Pages: [1]   Go Down
Author Topic: Speed of floating point operations -- test results  (Read 4747 times)
0 Members and 1 Guest are viewing this topic.
Columbus, Ohio USA
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 07, 2008, 12:58:39 pm by jmknapp » Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Columbus, Ohio USA
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Columbus, Ohio USA
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!  :smiley

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.
« Last Edit: April 09, 2008, 05:46:32 am by jmknapp » Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!  :smiley

Hey, I work for the government  smiley-wink

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.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Columbus, Ohio USA
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks for checking it out & changing the docs.
Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

So are floats and doubles identical?
Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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=
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and for most Arduino apps floats are more than sufficient
« Last Edit: April 11, 2008, 02:50:48 am by mem » Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"?
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink
« Last Edit: April 11, 2008, 09:48:13 am by mem » Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink

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

-- and to clarify, I mean code, not data.
« Last Edit: April 11, 2008, 10:39:16 am by Oracle » Logged

Pages: [1]   Go Up
Jump to: