Skip Menu |

This queue is for tickets about the Math-GSL CPAN distribution.

Report information
The Basics
Id: 96440
Status: resolved
Priority: 0/
Queue: Math-GSL

People
Owner: Nobody in particular
Requestors: DANAJ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Math::GSL::PowInt documentation and benchmarks
1. Typo in last sentence of description "avaible" => "available" 2. Am I completely missing the point of this? "This module is used to speed up arithmetic operations. The underlying code decomposes the multiplication in the most efficient way. Since it is implemented in XS (via SWIG), it should lend a large performance increase over the Perl builtin exponentiation operator '**'" This makes it sound like Perl's exponentiation is in pure Perl, which isn't the case. This module is about half the speed of the builtin for Perl 5.10.1 and 5.20.0 in my tests, but of course I am not testing every system. In many cases we're comparing GSL+wrappers vs. the C library's powl(). Perhaps there is an advantage in something other than performance, or performance on odd systems? Either way I think that paragraph needs to be rewritten. 3. Benchmark example attached. Results: Rate PowInt n^11 PowInt r^-2 PowInt n^4 PowInt n^2 native n^11 PowInt r^2 native r^-2 native n^2 native n^4 native r^2 PowInt n^11 3843/s -- -8% -10% -12% -19% -33% -59% -60% -61% -67% PowInt r^-2 4176/s 9% -- -2% -4% -12% -28% -56% -57% -58% -64% PowInt n^4 4278/s 11% 2% -- -2% -10% -26% -55% -55% -57% -64% PowInt n^2 4346/s 13% 4% 2% -- -8% -25% -54% -55% -56% -63% native n^11 4749/s 24% 14% 11% 9% -- -18% -50% -51% -52% -60% PowInt r^2 5767/s 50% 38% 35% 33% 21% -- -39% -40% -42% -51% native r^-2 9425/s 145% 126% 120% 117% 98% 63% -- -2% -5% -20% native n^2 9602/s 150% 130% 124% 121% 102% 67% 2% -- -4% -18% native n^4 9952/s 159% 138% 133% 129% 110% 73% 6% 4% -- -15% native r^2 11760/s 206% 182% 175% 171% 148% 104% 25% 22% 18% --
Subject: gsl-pow-bench.pl
#!/usr/bin/env perl use strict; use warnings; use Benchmark qw/:all/; use Math::GSL::PowInt qw/:all/; my $count = shift || -1; cmpthese($count, { "native n^2" => sub { my $s=0; for (1..1000) { $s += $_**2; } $s; }, "PowInt n^2" => sub { my $s=0; for (1..1000) { $s += gsl_pow_2($_); } $s; }, "native n^4" => sub { my $s=0; for (1..1000) { $s += $_**4; } $s; }, "PowInt n^4" => sub { my $s=0; for (1..1000) { $s += gsl_pow_4($_); } $s; }, "native n^11" => sub { my $s=0; for (1..1000) { $s += $_**11; } $s; }, "PowInt n^11" => sub { my $s=0; for (1..1000) { $s += gsl_pow_int($_,11); } $s; }, "native r^2" => sub { my $s=1.00001; for (1..1000) { $s = $s**2; } $s; }, "PowInt r^2" => sub { my $s=1.00001; for (1..1000) { $s = gsl_pow_2($s); } $s; }, "native r^2" => sub { my $s=1.00001; for (1..1000) { $s = $s**2; } $s; }, "PowInt r^2" => sub { my $s=1.00001; for (1..1000) { $s = gsl_pow_2($s); } $s; }, "native r^-2" => sub { my $s=1.00001; for (1..1000) { $s = $s**-2; } $s; }, "PowInt r^-2" => sub { my $s=1.00001; for (1..1000) { $s = gsl_pow_int($s,-2); } $s; }, });
On Fri Jun 13 19:05:19 2014, DANAJ wrote: Show quoted text
> 1. Typo in last sentence of description "avaible" => "available" > > 2. Am I completely missing the point of this? > > "This module is used to speed up arithmetic operations. The underlying > code decomposes the multiplication in the most efficient way. Since it > is implemented in XS (via SWIG), it should lend a large performance > increase over the Perl builtin exponentiation operator '**'" > > This makes it sound like Perl's exponentiation is in pure Perl, which > isn't the case. This module is about half the speed of the builtin > for Perl 5.10.1 and 5.20.0 in my tests, but of course I am not testing > every system. In many cases we're comparing GSL+wrappers vs. the C > library's powl(). Perhaps there is an advantage in something other > than performance, or performance on odd systems? > > Either way I think that paragraph needs to be rewritten. > > 3. Benchmark example attached. Results: > > Rate PowInt n^11 PowInt r^-2 PowInt n^4 PowInt n^2 native n^11 PowInt > r^2 native r^-2 native n^2 native n^4 native r^2 > PowInt n^11 3843/s -- -8% -10% -12% > -19% -33% -59% -60% -61% -67% > PowInt r^-2 4176/s 9% -- -2% -4% > -12% -28% -56% -57% -58% -64% > PowInt n^4 4278/s 11% 2% -- -2% > -10% -26% -55% -55% -57% -64% > PowInt n^2 4346/s 13% 4% 2% -- > -8% -25% -54% -55% -56% -63% > native n^11 4749/s 24% 14% 11% 9% > -- -18% -50% -51% -52% -60% > PowInt r^2 5767/s 50% 38% 35% 33% > 21% -- -39% -40% -42% -51% > native r^-2 9425/s 145% 126% 120% 117% > 98% 63% -- -2% -5% -20% > native n^2 9602/s 150% 130% 124% 121% > 102% 67% 2% -- -4% -18% > native n^4 9952/s 159% 138% 133% 129% > 110% 73% 6% 4% -- -15% > native r^2 11760/s 206% 182% 175% 171% > 148% 104% 25% 22% 18% --
Howdy, Can you try exponentiation with some large values? Like n^1000 ?
With standard doubles, I'm not seeing any cases where GSL is faster. With long doubles, GSL is faster with exponents of 8 or higher (I did not measure the exact cutoff), but of course it is losing precision. In both cases GSL loses the option of compile phase constant optimization. Again noting this is only one platform. gp > 1.000001 ^ 250000 %1 = 1.2840252561846814315783154928718272166 Perl 5.20.0 standard build, idle i3930K: time perl -MMath::GSL::PowInt=:all -E 'my($b,$e)=(1.000001,250000); say $b**$e; for (1..100_000_000) { $b**$e }' 1.28402525615827 real 0m8.329s user 0m8.282s sys 0m0.000s time perl -MMath::GSL::PowInt=:all -E 'my($b,$e)=(1.000001,250000); say gsl_pow_int($b,$e); for (1..100_000_000) { gsl_pow_int($b,$e) }' 1.28402525616544 real 0m11.427s user 0m11.251s sys 0m0.001s Perl 5.21.0 with long doubles: time perl -MMath::GSL::PowInt=:all -E 'my($b,$e)=(1.000001,250000); say $b**$e; for (1..100_000_000) { $b**$e }' 1.28402525618468923 real 0m27.110s user 0m26.867s sys 0m0.003s time perl -MMath::GSL::PowInt=:all -E 'my($b,$e)=(1.000001,250000); say gsl_pow_int($b,$e); for (1..100_000_000) { gsl_pow_int($b,$e) }' 1.28402525616543861 real 0m14.188s user 0m14.068s sys 0m0.001s Hard coding the numbers results in no change for GSL, but runs in 1.8s for native. For the attached benchmark: Without long double (5.20.0, idle i3930K, GSL 1.15, count -5): result for 2000: native: 7.70379315683258e+227 GSL: 7.70379315683273e+227 Rate PowInt n^2 native n^2 Rate PowInt n^2 native n^2 PowInt n^2 8202/s -- -54% native n^2 17737/s 116% -- Rate PowInt n^7 native n^7 PowInt n^7 7878/s -- -16% native n^7 9327/s 18% -- Rate PowInt n^8 native n^8 PowInt n^8 8052/s -- -14% native n^8 9309/s 16% -- Rate PowInt n^30 native n^30 PowInt n^30 7286/s -- -21% native n^30 9240/s 27% -- Rate PowInt n^250 native n^250 PowInt n^250 7044/s -- -23% native n^250 9116/s 29% -- Rate PowInt n^1000 native n^1000 PowInt n^1000 6967/s -- -23% native n^1000 9102/s 31% -- Rate PowInt n^2048 native n^2048 PowInt n^2048 6888/s -- -25% native n^2048 9134/s 33% -- With long double (5.21.0, idle i3930K, GSL 1.15, count -5): result for 2000: native: 7.70379315683204983e+227 GSL: 7.70379315683273184e+227 Rate PowInt n^2 native n^2 PowInt n^2 6070/s -- -50% native n^2 12092/s 99% -- Rate PowInt n^7 native n^7 PowInt n^7 6001/s -- -50% native n^7 11955/s 99% -- Rate native n^8 PowInt n^8 native n^8 3464/s -- -43% PowInt n^8 6035/s 74% -- Rate native n^30 PowInt n^30 native n^30 3456/s -- -25% PowInt n^30 4601/s 33% -- Rate native n^250 PowInt n^250 native n^250 3364/s -- -23% PowInt n^250 4392/s 31% -- Rate native n^1000 PowInt n^1000 native n^1000 3369/s -- -23% PowInt n^1000 4390/s 30% -- Rate native n^2048 PowInt n^2048 native n^2048 3299/s -- -29% PowInt n^2048 4635/s 41% --
Subject: gsl-pow-bench2.pl
#!/usr/bin/env perl use strict; use warnings; use Benchmark qw/:all/; use Math::GSL::PowInt qw/:all/; my $count = shift || -1; my @tnum = map { 1.2 + 0.1/$_ } 1..1000; my $s; print "result for 2000:\n"; print "native: ", native_exp_sub(2000)->(), "\n"; print "GSL: ", gsl_exp_sub(2000)->(), "\n"; cmpthese($count, { "native n^2" => sub { $s=0; $s += $_**2 for @tnum; $s; }, "PowInt n^2" => sub { $s=0; $s += gsl_pow_2($_) for @tnum; $s; }, }); cmpthese($count, { "native n^7" => sub { $s=0; $s += $_**7 for @tnum; $s; }, "PowInt n^7" => sub { $s=0; $s += gsl_pow_7($_) for @tnum; $s; }, }); cmpthese($count, { "native n^8" => sub { $s=0; $s += $_**8 for @tnum; $s; }, "PowInt n^8" => sub { $s=0; $s += gsl_pow_8($_) for @tnum; $s; }, }); cmpthese($count, { "native n^30" => native_exp_sub(30), "PowInt n^30" => gsl_exp_sub(30), }); cmpthese($count, { "native n^250" => native_exp_sub(250), "PowInt n^250" => gsl_exp_sub(250), }); cmpthese($count, { "native n^1000" => native_exp_sub(1000), "PowInt n^1000" => gsl_exp_sub(1000), }); cmpthese($count, { "native n^2048" => native_exp_sub(2048), "PowInt n^2048" => gsl_exp_sub(2048), }); sub native_exp_sub { my $exp = shift; return sub { my $s = 0; $s += $_**$exp for @tnum; $s; }; } sub gsl_exp_sub { my $exp = shift; return sub { my $s = 0; $s += gsl_pow_int($_,$exp) for @tnum; $s; }; }
Updated Math::GSL POD to link to these benchmarks and remark that there is not much point in the module. Thanks for the benchmarks, Dana! On Fri Jun 13 19:05:19 2014, DANAJ wrote: Show quoted text
> 1. Typo in last sentence of description "avaible" => "available" > > 2. Am I completely missing the point of this? > > "This module is used to speed up arithmetic operations. The underlying > code decomposes the multiplication in the most efficient way. Since it > is implemented in XS (via SWIG), it should lend a large performance > increase over the Perl builtin exponentiation operator '**'" > > This makes it sound like Perl's exponentiation is in pure Perl, which > isn't the case. This module is about half the speed of the builtin > for Perl 5.10.1 and 5.20.0 in my tests, but of course I am not testing > every system. In many cases we're comparing GSL+wrappers vs. the C > library's powl(). Perhaps there is an advantage in something other > than performance, or performance on odd systems? > > Either way I think that paragraph needs to be rewritten. > > 3. Benchmark example attached. Results: > > Rate PowInt n^11 PowInt r^-2 PowInt n^4 PowInt n^2 native n^11 PowInt > r^2 native r^-2 native n^2 native n^4 native r^2 > PowInt n^11 3843/s -- -8% -10% -12% > -19% -33% -59% -60% -61% -67% > PowInt r^-2 4176/s 9% -- -2% -4% > -12% -28% -56% -57% -58% -64% > PowInt n^4 4278/s 11% 2% -- -2% > -10% -26% -55% -55% -57% -64% > PowInt n^2 4346/s 13% 4% 2% -- > -8% -25% -54% -55% -56% -63% > native n^11 4749/s 24% 14% 11% 9% > -- -18% -50% -51% -52% -60% > PowInt r^2 5767/s 50% 38% 35% 33% > 21% -- -39% -40% -42% -51% > native r^-2 9425/s 145% 126% 120% 117% > 98% 63% -- -2% -5% -20% > native n^2 9602/s 150% 130% 124% 121% > 102% 67% 2% -- -4% -18% > native n^4 9952/s 159% 138% 133% 129% > 110% 73% 6% 4% -- -15% > native r^2 11760/s 206% 182% 175% 171% > 148% 104% 25% 22% 18% --