6 Einträge, 1 Seite |
1
2
3
my @array = qw(35 73 745 23 85);
my $zahl = (sort{$a <=> $b} @array)[-1];
print $zahl;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
use Benchmark qw(cmpthese);
use List::Util qw(max);
@a = qw(35 73 745 23 85);
@a = (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,);
cmpthese(-1, {
"max" => sub { my $max = max @a },
"linear" => sub {
my $max = $a[0];
for (@a) {
$max = $_ if $_ > $max;
}
},
"sort" => sub {
my $max = (sort{$a <=> $b} @a)[-1];
}
}
);
1
2
3
4
Rate linear sort max
linear 49778/s -- -23% -92%
sort 64869/s 30% -- -90%
max 649176/s 1204% 901% --
6 Einträge, 1 Seite |