Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Print Number With Implied Decimal Point

by Eliya (Vicar)
on Apr 18, 2012 at 14:51 UTC ( #965724=note: print w/ replies, xml ) Need Help??


in reply to Re: Print Number With Implied Decimal Point
in thread Print Number With Implied Decimal Point

substr will be faster though.

Yes, by several orders of magnitude...

use Benchmark qw(cmpthese); use Math::BigFloat; Math::BigFloat->precision(-2); my $number = "999999999999999999999900"; cmpthese -1, { substr => sub { my $num=$number; substr($num,-2,0) = '.'; }, BigFloat => sub { my $num=$number; Math::BigFloat->new($num)/100; +}, }; __END__ Rate BigFloat substr BigFloat 3794/s -- -100% substr 1668189/s 43874% --

And that doesn't even involve accessing or printing out the constructed BigFloat again.


Comment on Re^2: Print Number With Implied Decimal Point
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965724]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-08-21 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (142 votes), past polls