Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: sprintf vs. substr (for zero-padded values)

by ferrency (Deacon)
on Jul 15, 2002 at 20:43 UTC ( #181913=note: print w/replies, xml ) Need Help??

in reply to sprintf vs. substr (for zero-padded values)

Note that a more accurate benchmark of one and two above would test numbers of all lengths, not just three digits. One method may be faster or slower for shorter or longer numbers.

I'm inclined to agree that the speed difference would most likely be small enough that it wouldn't be the primary deciding factor for me in this case. I prefer the sprintf method for ease of implementation and maintenance. If you add in the cost of calling an encapsulated zero-padder instead of printf, your times may be even closer.


  • Comment on Re: sprintf vs. substr (for zero-padded values)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2019-11-12 15:57 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (66 votes). Check out past polls.