> close STDERR;
> open (STDERR, ">NUL");

That's what I wanted to do.

>
> timethese( 5000   , {
>      'NumsAsStrings' => 'for ( $i = "001"; $i lt "501"; $i++ ) {print
STDERR $i}',
>      'NumsAsNums1'   => 'for ( 1 .. 501 ) {printf STDERR "%03d", $_};',
>      'NumsAsNums2'   => 'for ( $i=1; $i<501;$i++) {printf STDERR "%03d",
$i}'
>     });
>
> __END__
>
> Benchmark: timing 5000 iterations of NumsAsNums1, NumsAsNums2,
NumsAsStrings...
> NumsAsNums1: 16 wallclock secs (15.33 usr +  0.02 sys = 15.35 CPU) @
325.69/s (n=5000)
> NumsAsNums2: 19 wallclock secs (19.19 usr +  0.00 sys = 19.19 CPU) @
260.59/s (n=5000)
> NumsAsStrings:  5 wallclock secs ( 5.63 usr +  0.02 sys =  5.65 CPU) @
885.27/s (n=5000)
>

perldoc -f printf

   Don't fall into the trap of using a `printf()' when a
   simple `print()' would do. The `print()' is more
   efficient and less error prone.

I didn't know it made _that_ much of a difference, especially against the
overhead of creating and updating $i each time. At least the (1..501) code
has the lowest golf score :)

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to