Front page | perl.beginners |
Postings from February 2002
RE: finding max value
Thread Previous
|
Thread Next
From:
Jeremy Vinding
Date:
February 13, 2002 08:58
Subject:
RE: finding max value
Message ID:
GNEBJNPEEJMMLILBFEBHIEBJDAAA.jvinding@aol.com
there must be a flaw in my test here:
Benchmark: timing 1000000 iterations of for 10_000 elems, for 20 elems, sort
10_000 elems, sort 20 elems...
for 10_000 elems: 6 wallclock secs ( 4.75 usr + 0.00 sys = 4.75 CPU) @
210526.32/s (n=1000000)
for 20 elems: 6 wallclock secs ( 4.86 usr + 0.00 sys = 4.86 CPU) @
205761.32/s (n=1000000)
sort 10_000 elems: 2 wallclock secs ( 2.74 usr + 0.01 sys = 2.75 CPU) @
363636.36/s (n=1000000)
sort 20 elems: 4 wallclock secs ( 2.71 usr + 0.00 sys = 2.71 CPU) @
369003.69/s (n=1000000)
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