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
dc25479c » Jonathan Leto 2008-10-02 WIP 1 #!/usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use Benchmark;
df2d8f25 » Jonathan Leto 2008-10-03 Refactor vector vs. array s... 6 use Math::GSL::Vector;
7 use Math::GSL::RNG;
8 use List::Util qw/max min/;
dc25479c » Jonathan Leto 2008-10-02 WIP 9
10 my $rng = Math::GSL::RNG->new;
df2d8f25 » Jonathan Leto 2008-10-03 Refactor vector vs. array s... 11 my $num = shift || 10000;
12 my @stuff = map { $rng->get() } (1..$num);
dc25479c » Jonathan Leto 2008-10-02 WIP 13 my $vector = Math::GSL::Vector->new([@stuff]);
14
df2d8f25 » Jonathan Leto 2008-10-03 Refactor vector vs. array s... 15 my $runs = shift || 50_000;
16 timethese($runs, {
17 'min - List::Util ' => sub { min(@stuff) },
18 'min of Math::GSL vector ' => sub { $vector->min },
19 });
20 timethese($runs, {
21 'max - List::Util ' => sub { max(@stuff) },
22 'max of Math::GSL vector ' => sub { $vector->max },
dc25479c » Jonathan Leto 2008-10-02 WIP 23 });