« blib/lib/Benchmark/Perl/Formance/Plugin/FibOO.pm
↑ Summary
blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsMouse.pm »
| 1 | package Benchmark::Perl::Formance::Plugin::MatrixReal; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:SCHWIGON'; | |||||||||
| 3 | # ABSTRACT: benchmark plugin - MatrixReal - Pure Perl matrix operations | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | our $VERSION = "0.001"; | |||||||||
| 10 | |||||||||||
| 11 | ############################################################# | ||||||||||
| 12 | # # | ||||||||||
| 13 | # Benchmark Code ahead - Don't touch without strong reason! # | ||||||||||
| 14 | # # | ||||||||||
| 15 | ############################################################# | ||||||||||
| 16 | |||||||||||
| 17 | 2 | ▶ | use Benchmark ':hireswallclock'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Math::MatrixReal; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | sub matrix_operations | ||||||||||
| 21 | 1 | ▶ | { | ||||||||
|
Subroutine
matrix_operations: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 22 | 1 | my ($options) = @_; | |||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | my @sizes = $options->{fastmode} ? (5) : (30); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 1 | my $count = 2000; | |||||||||
| 26 | |||||||||||
| 27 | 1 | srand(42); # ensure same data for benchmarking | |||||||||
| 28 | 1 | my %matrices = map { ( $_ => Math::MatrixReal->new_random($_) ) } @sizes; | |||||||||
| 29 | |||||||||||
| 30 | 1 | my %results; | |||||||||
| 31 | 1 | for my $size ( keys %matrices ) | |||||||||
| 32 | { | ||||||||||
| 33 | # TODO: seed random generator! | ||||||||||
| 34 | 1 | my $sizestr = sprintf("%03d",$size); | |||||||||
| 35 | 1 | my $matrix = $matrices{$size}; | |||||||||
| 36 | 1 | my ($r,$c) = $matrix->dim; | |||||||||
| 37 | |||||||||||
| 38 | # taken from https://metacpan.org/source/LETO/Math-MatrixReal-2.12/example/bench.pl | ||||||||||
| 39 | 1 | ▶ | $results{det}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix->det } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 1 | ▶ | $results{det_LR}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix->decompose_LR->det_LR } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1 | ▶ | $results{inverse}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix->inverse() } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 1 | ▶ | $results{invert_LR}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix->decompose_LR->invert_LR } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 1 | ▶ | $results{matrix_squared}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix ** 2 } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 1 | ▶ | $results{to_negative_one}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix ** -1 } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 1 | ▶ | $results{matrix_times_itself}{$sizestr} = { goal => $size, Benchmark => [@{ timeit $count, sub { $matrix * $matrix } }] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | } | ||||||||||
| 47 | 1 | return \%results; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub main | ||||||||||
| 51 | 1 | ▶ | { | ||||||||
|
Subroutine
main: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 52 | 1 | my ($options) = @_; | |||||||||
| 53 | |||||||||||
| 54 | 1 | return matrix_operations($options) | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||