On Tue, Mar 27, 2001 at 04:19:08PM +0100, Simon Wilcox wrote:

> I thought I would play around with Benchmark.pm, because I don't use it 
> nearly often enough, so I made this script:
> 
> @th=(qw(th st nd rd),("th")x16)x2; $th[31]="st";
> sub th{(($_[0]-10-$_[0]%10)/10%10)?(qw(th st nd rd),('th')x6)[$_[0]%10]:"th"}
> 
> Benchmark: timing 100000 iterations of Array, Sub...
>       Array:  3 wallclock secs ( 3.33 usr +  0.09 sys =  3.42 CPU)
>         Sub:  6 wallclock secs ( 5.27 usr +  0.06 sys =  5.33 CPU)
> 
> So - Did I get this heinously wrong or is MBM's sub really a lot slower ?

No, you got it right.  You would expect the sub version to be slower, as it
has to make a subroutine call and do some calculations every time, whereas
the array version pre-calculates everything and then just does a tonne of
comparitively inexpensive array lookups.

-- 
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

    This is a signature.  There are many like it but this one is mine.

** I read encrypted mail first, so encrypt if your message is important **

PGP signature

Reply via email to