Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

fastes way to print floats with fixed decimal places

by Zac (Initiate)
on Jul 07, 2011 at 17:39 UTC ( [id://913231] : perlquestion . print w/replies, xml ) Need Help??

Zac has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

to print floats with fixed decimal places normaly printf is used

eg:

 printf("%.3f %.3f %.3f\n",$a,$b,$c);

is there a faster way to get the same result ??

Have fun

Zac

Replies are listed 'Best First'.
Re: fastes way to print floats with fixed decimal places
by Somni (Friar) on Jul 07, 2011 at 19:01 UTC
    It is indeed possible to speed up floating point conversion. I actually read a blog article (with decent links to further information) on recent advances on the subject; see here.

    However, I seriously doubt this is truly the bottleneck in your program. Have you profiled? Are you asking for improvement in CPU speed, or perhaps in programmer time spent using and understanding the conversion?

      An interesting Article! thanks
Re: fastes way to print floats with fixed decimal places
by blue_cowdawg (Monsignor) on Jul 07, 2011 at 18:06 UTC
        is there a faster way to get the same result ??

    I'm not sure I understand the question.... faster how?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      faster than using fprintf of course.
Re: fastes way to print floats with fixed decimal places
by Anonymous Monk on Jul 07, 2011 at 18:44 UTC

    First, show the profiling results that illuminate how formatting the floats into a string is a significant contributor to the runtime of your program. Only then should you care about its speed of execution.