Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 rifling through the Monastery: (4)
As of 2020-10-28 02:29 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (259 votes). Check out past polls.