Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

(MeowChow) Re5: Help with number conversion

by MeowChow (Vicar)
on Apr 03, 2002 at 10:15 UTC ( #156274=note: print w/replies, xml ) Need Help??

in reply to Re: Re: •Re: Re: Help with number conversion
in thread Help with number conversion

You can get a substantial improvement over the builtin sprintf with:
substr "000$num", -3
use strict; use Benchmark qw(cmpthese); my $num = 42; cmpthese (-3, { sprintf => sub { sprintf '%03d', $num }, concat => sub { ('0' x (3 - length $num)).$num }, substr => sub { substr "000$num", -3 }, }); Rate concat sprintf substr concat 244047/s -- -10% -36% sprintf 269956/s 11% -- -29% substr 381628/s 56% 41% --
               s aamecha.s a..a\u$&owag.print

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://156274]
[Discipulus]: good morning folks!
choroba mornings back
[Corion]: Hi choroba!
[Corion]: And Discipulus!
Corion arrived back from London. Always nice to meet people again, even if it's just once per year.
[Corion]: Also, dk contributed some cool stuff to App::ShaderToy, like menu settings and real fullscreen, eliminating many of my #TO-DO comments ;)
[Corion]: I hope you spent the four days well without me online ;-D

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2016-12-06 08:19 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (101 votes). Check out past polls.