Leser: 2
|< 1 2 3 >| | 22 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use Benchmark;
my @numbers;
for (1..10000) {
my $random = int( rand(9000)) + 5;
push @numbers, $random;
}
print scalar @numbers, " numbers created !\n";
my $iterations = 100;
timethese($iterations, {
"Schwartz" => sub {
my @sorted = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { my $num = $_; $num =~ /\d+/; [ $_, $num ]; } @numbers }
});
timethese($iterations, {
"Normal sort" => sub {
my @sorted = sort {$b <=> $a} @numbers;
}
});
exit;
Quote10000 numbers created !
Benchmark: timing 100 iterations of Schwartz...
Schwartz: 17 wallclock secs (13.40 usr + 0.18 sys = 13.58 CPU) @ 7.36/s (n=100)
Benchmark: timing 100 iterations of Normal sort...
Normal sort: 2 wallclock secs ( 1.50 usr + 0.04 sys = 1.54 CPU) @ 64.94/s (n=100)
my $num = $_; $num =~ /\d+/; [ $_, $num ];
map { my $num = $_; $num =~ /\d+/; [ $_, $num ]; } @numbers
sort { $b->[1] <=> $a->[1] }
my @sorted = map { $_->[0] }
@filesSorted = sort { -s $a <=> -s $b } @files
|< 1 2 3 >| | 22 Einträge, 3 Seiten |