File: bench.pl

package info (click to toggle)
libmath-matrixreal-perl 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,120 kB
  • sloc: perl: 2,837; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download
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
29
30
31
32
33
34
35
#!/usr/bin/perl -w

use Math::MatrixReal;
use Benchmark;

my @matrices = map { Math::MatrixReal->new_random($_) } qw(5 10 15 20);

my $iter = 2000;

for my $matrix ( @matrices ) {
        my ($r,$c) = $matrix->dim;
        print "Benchmarking $r x $c matrix\n";

        timethese($iter, {
              'overload_left_multiply  '     => sub { 7*$matrix                          },
              'overload_right_multiply '     => sub { $matrix*7                          },

               # this is twice as fast, but gives you CPT
              'function_multiply       '     => sub { $matrix->multiply_scalar($matrix,7)},
        });

        timethese($iter,
            { 
              'matrix_squared     '     => sub { $matrix ** 2                       },
              'matrix_times_itself'     => sub { $matrix * $matrix                  },
              'det                '     => sub { $matrix->det                       },
              'det_LR             '     => sub { $matrix->decompose_LR->det_LR      },
              'inverse            '     => sub { $matrix->inverse()                 },
              'to_negative_one    '     => sub { $matrix ** -1                      },
              'invert_LR          '     => sub { $matrix->decompose_LR->invert_LR   },
            });



}