develooper Front page | perl.beginners | Postings from February 2002

Re: finding max value

Thread Previous | Thread Next
From:
Carl Franks
Date:
February 14, 2002 01:26
Subject:
Re: finding max value
Message ID:
E16bI9g-00068S-00@spielberg.vip.uk.com
I can't tell by this code alone, but does the benchmark time the entire 
script that's running, or just the iterate/sort part?

i.e. is the 'rand' function timed also, and will the time difference between
generating 20 and 10,000 numbers mess up the results?

Sorry I can't test this myself, I'm at a computer w/out perl :O !!

Cheers, Carl
Please don't cc me. I'm on the list.


>
> my @bob = rand for (1..20);
> my @joe = rand for (1..10_000);
> sub maxOne
> {
>     my $max = (sort {$b<=>$a} @bob)[0]
> }
> sub maxTwo
> {
>     my $max = (sort {$b<=>$a} @joe)[0]
> }
> sub maxThree
> {
>     my $max = $bob[0];
>     for (@bob)
>     {
>         $max = $_ if $_ > $max
>     }
> }
> sub maxFour
> {
>     my $max = $joe[0];
>     for (@joe)
>     {
>         $max = $_ if $_ > $max
>     }
> }


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About