-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #831 from shawnlaffan/faster_RPE2_maybe
Speed improvements for PE, RPE etc
- Loading branch information
Showing
11 changed files
with
369 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use Benchmark qw {:all}; | ||
use 5.016; | ||
use Data::Dumper; | ||
|
||
use List::Util qw {sum}; | ||
|
||
my @keys = 'a' .. 'zzm'; | ||
my %base_hash; | ||
@base_hash{@keys} = map {rand() + $_} (1..@keys); | ||
|
||
say sum_foreach(); | ||
say lu_sum(); | ||
say lu_sum0(); | ||
say lu_reduce(); | ||
say pf_values(); | ||
|
||
|
||
cmpthese ( | ||
-2, | ||
{ | ||
foreach => \&sum_foreach, | ||
lu_sum => \&lu_sum, | ||
lu_sum0 => \&lu_sum0, | ||
lu_reduce => \&lu_reduce, | ||
pf_values => \&pf_values, | ||
} | ||
); | ||
|
||
sub sum_foreach { | ||
my $sum; | ||
foreach (values %base_hash) { | ||
$sum += $_; | ||
} | ||
$sum; | ||
} | ||
|
||
sub lu_sum { | ||
my $sum = sum values %base_hash; | ||
$sum; | ||
} | ||
|
||
sub lu_sum0 { | ||
my $sum = sum 0, values %base_hash; | ||
$sum; | ||
} | ||
|
||
sub lu_reduce { | ||
my $sum = List::Util::reduce {$a + $b} values %base_hash; | ||
$sum; | ||
} | ||
|
||
sub pf_values { | ||
my $sum; | ||
$sum += $_ for values %base_hash; | ||
$sum; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.