my $cnt_sort = 0; my $cnt_sort_schwartz = 0; my $comparison = 0; my @array = ( [25,1], [3,7], [1,2], [2,4], [2,2], [35,34] ); # Native my @dummy = sort{ $comparison++; helper($a) <=> helper($b) }@array ; print "Anzahl der Vergleiche: $comparison\n"; print "Anzahl der Aufrufe cnt_sort: $cnt_sort\n"; # nach Schwartz $comparison = 0; my @dummy_schwartz = map{$_->[0]} sort{ $comparison++; $a->[1] <=> $b->[1] } map{[$_, helper_schwartz($_)]} @array; print "\nAnzahl der Vergleiche: $comparison\n"; print "Anzahl der Aufrufe cnt_sort_schwartz: $cnt_sort_schwartz\n"; sub helper{ my $ref = shift; $cnt_sort++; return abs($ref->[1] - $ref->[0]); } sub helper_schwartz{ my $ref = shift; $cnt_sort_schwartz++; return abs($ref->[1] - $ref->[0]); } __END__ Anzahl der Vergleiche: 8 Anzahl der Aufrufe cnt_sort: 16 Anzahl der Vergleiche: 8 Anzahl der Aufrufe cnt_sort_schwartz: 6