Improve Monte typemaps
[Math-GSL.git] / examples / vector / dot_product
blob0fd8a8cb9ce7f941d8845012f0ca4115cf6ccd89
1 #!/usr/bin/perl -w
3 use strict;
4 use warnings;
5 use Benchmark;
6 use Math::GSL::Vector qw/:all/;
7 use Math::GSL::Errno qw/:all/;
8 use Math::GSL::RNG qw/:all/;
9 use Math::GSL::BLAS qw/:all/;
10 use Data::Dumper;
12 my $count = shift || 500_000;
13 my $dim = shift || 10;
14 my $rng = Math::GSL::RNG->new;
15 my @nums = map { $rng->get % 100 } (1..$dim);
17 my $x = Math::GSL::Vector->new( \@nums );
18 my $y = $x->copy + int(rand(100));
20 warn Dumper [ $x->as_list ];
21 warn Dumper [ $y->as_list ];
23 warn Dumper [ pp_dot($x,$y) ];
24 warn Dumper [ gsl_dot($x,$y) ];
26 timethese(
27 $count, {
28 'pp_dot ' => sub { pp_dot($x,$y) },
29 'gsl_dot ' => sub { gsl_dot($x,$y) },
30 'overload_dot ' => sub { $x * $y },
31 });
33 sub gsl_dot {
34 my ($x,$y) = @_;
35 my ($status,$dot) = gsl_blas_ddot($x->raw,$y->raw);
36 return $dot;
40 sub pp_dot {
41 my ($x,$y) = @_;
42 return Math::GSL::Vector::dot_product_pp($x,$y);