Which one is Faster and Recommanded to usage?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm know two function dtostrf() and sprintf() are Convert Float to String.

Now my question is Which one is Faster and Re commanded to usage?

 

------

eR

শূন্য  - The ZeRo

Last Edited: Tue. Nov 17, 2015 - 05:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think dtostrf() is faster (highly optimized avr libm code), and sprintf() is more standard (dtostrf() is not standard and not implemented for many environments.  Arduino folk had to re-implement dtosrf() (USING sprintf()) on ARM for backward compatbility with AVR.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The difference isn't so much speed (though you could do some cycle counts in the simulator). It's a question of flash size. Dtostrf is considerably smaller, use it if you don't have the space for sprintf(%f). 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm know two function dtostrf() and sprintf() are Convert Float to String.

Now my question is Which one is Faster and Re commanded to usage?

 

Now, why can't you create simple test programs that do it both ways, and compare program size and number of cycles (using AVRstudio simulator)?  That's what we are going to recommend anyway.  This kind of approach and thinking is important if you are indeed going to do microcontroller programming!

 

Once you do the above exercise, then repeat with several different data values, and compare the resulting processor cycles used.  Let us know how surprising your results are. ;)

 

And then:  Tell more about your use of floating point in a supposed Mega8 application.  Is it really necessary?  or does the use of floating point do nothing but make your program much larger and much slower?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.