Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: zero padding

by sh1tn (Priest)
on Feb 09, 2005 at 22:33 UTC ( [id://429539]=note: print w/replies, xml ) Need Help??


in reply to zero padding

Not better performance solution:
use strict; use Benchmark; my @convert; for(0..10000){ $convert[$_] = '0' x (4 - length$_) . $_ } my ($val1,$val2) = (int rand(10000),int rand(10000)); timethese 2_000_000 => { array => sub { @convert[$val1,$val2] }, nobull => sub { $val1 * 10000 + $val2 } } #where connectm can be #sub connectm { # my ($val1,$val2) = @_; # @convert[$val1,$val2] #} __END__ Benchmark: timing 2000000 iterations of array, nobull... array: 2 wallclock secs ( 0.78 usr + 0.00 sys = 0.78 CPU) @ 25 +57544.76/s (n=2000000) nobull: 1 wallclock secs ( 0.52 usr + 0.00 sys = 0.52 CPU) @ 38 +83495.15/s (n=2000000)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found