File: bench_mult.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 (28 lines) | stat: -rwxr-xr-x 814 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
#!/usr/bin/perl -w

use Math::MatrixReal;
use Benchmark;

my @matrices = map { Math::MatrixReal->new_random($_) } qw(10 20 50 100 200 300);

my $iter = 2000;

for my $matrix ( @matrices ) {
        my ($r,$c) = $matrix->dim;
        my $b = $matrix->new_random($r);

        print "Benchmarking $r x $c matrix\n";

        timethese($iter, {
              '*       '         => sub { $matrix*$b },
              'multiply'         => sub { $matrix->multiply($b) },
        });

        timethese($iter,
            { 
              'matrix_squared        '     => sub { $matrix ** 2                       },
              'matrix_times_itself   '     => sub { $matrix * $matrix                  },
              'matrix_multiply_itself'     => sub { $matrix->multiply($matrix)         },
            }
        )
}