in reply to how to choose the greater or equal number in array
Hello lakshu,
Welcome to the Monastery. Although the fellow Monks have answered your question I would like to add something small here.
Just for reference your question was asked before Finding the max()/min(). If you are interested in efficiency between List::Util core module and also the List::MoreUtils which is not a core module. Sample bellow:
#!/usr/bin/perl use strict; use warnings; use List::Util qw( min max ); use List::MoreUtils qw( minmax ); # use Benchmark qw(:all) ; # WindowsOS use Benchmark::Forking qw( timethese cmpthese ); # UnixOS sub simpleUtil { my (@numbers) = @_; my $min = min @numbers; my $max = max @numbers; return $min, $max; } sub moreUtil { my (@numbers) = @_; my ($min, $max) = minmax @numbers; return $min, $max; } my @test_array = (3,6,7,6,3,10,5,6,2,10); my $results = timethese(1000000000, { SimpleUtil => simpleUtil(@test_a +rray), MoreUtil => moreUtil(@test_array), }, 'none'); cmpthese( $results ); __END__ $ perl test.pl Rate 10 2 SimpleUtil 10 278551532/s -- -31% -57% 2 406504065/s 46% -- -37% SimpleUtil 645161290/s 132% 59% --
Hope this helps, BR.
|
|---|