public
Description: Perl interface to the GNU Scientific Library
Homepage: http://leto.net/code/Math-GSL
Clone URL: git://github.com/leto/math--gsl.git
Click here to lend your support to: math--gsl and make a donation at www.pledgie.com !
math--gsl / examples / vector / speed
100755 24 lines (20 sloc) 0.584 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl -w
 
use strict;
use warnings;
use Benchmark;
use Math::GSL::Vector;
use Math::GSL::RNG;
use List::Util qw/max min/;
 
my $rng = Math::GSL::RNG->new;
my $num = shift || 10000;
my @stuff = map { $rng->get() } (1..$num);
my $vector = Math::GSL::Vector->new([@stuff]);
 
my $runs = shift || 50_000;
timethese($runs, {
    'min - List::Util ' => sub { min(@stuff) },
    'min of Math::GSL vector ' => sub { $vector->min },
});
timethese($runs, {
    'max - List::Util ' => sub { max(@stuff) },
    'max of Math::GSL vector ' => sub { $vector->max },
});