Hi,
I need to use the beta function with the GSL version 1.6. I have tried
to compute it either using gsl_sf_beta or by using the relation
Beta(w,z) = Gamma(w)*Gamma(z)/Gamma(w,z) and calling (gsl_sf_gamma).
I measured the CPU time to compute each solution using the rdtsc
assembly function (my processor is an Intel P4).
The results where quite surprising: using the Gamma function
(gsl_sf_gamma) to compute the Beta function seems to be 2x more
efficient than using directly the Beta function (gsl_sf_beta).
To compare the CPU times, I have made a small loop (10 times) that calls
each solution. Here are the results:
CPU frequency : 3.19213e+09
Beta CPU Gamma CPU
Loop 1
150736 11936
Loop 2
8632 4896
Loop 3
8280 4760
Loop 4
8280 4752
Loop 5
8288 4752
Loop 6
8536 4760
Loop 7
8296 4760
Loop 8
8280 4760
Loop 9
8280 4760
Loop 10
8280 4760
I’m also surprise to notice that the first iteration costs much more CPU
time than the following iterations.
I’ve attached my C++ test to my mail.
Regards,
Helfer Thomas
// gsl_test_beta.cxx
// Castelier Etienne
// 19 jan 2007
//
// Test de la fonction Beta de la GSL
//
#include <iostream>
#include <gsl/gsl_sf_gamma.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <sys/times.h>
#include <asm/msr.h>
class IntelTimer {
public:
IntelTimer( void ):_frequency(1.0)
{
find_frequency();
}
inline void start( void ){
rdtsc(_click_start.n32[0],_click_start.n32[1]);
}
inline void stop( void ){
rdtsc(_click_stop.n32[0],_click_stop.n32[1]);
}
unsigned long long get_click( void ){
return (_click_stop.n64-_click_start.n64);
}
inline void find_frequency( void ){
time_t initial, final;
int dummy=2;
initial = time(0);
start();
do {
dummy+=2;
}
while(time(0)==initial);
// On est au debut d'un cycle d'une seconde !!!
initial = time(0);
start();
do {
dummy+=2;
}
while(time(0)==initial);
stop();
final=time(0);
// _frequency=get_click()/double(final-initial);
_frequency=get_click();
std::cerr << "CPU frequency : "<< _frequency << std::endl;
}
private:
union
{
unsigned long int n32[2] ;
unsigned long long n64 ;
} _click_start;
union
{
unsigned long int n32[2] ;
unsigned long long n64 ;
} _click_stop;
double _frequency ;
};
using namespace std;
// test
void test_gsl() {
double Ib,Ig;
double z,w,mf,mm;
IntelTimer timer;
long long t1,t2;
int n,i;
mm=4.9;
mf=3.9;
w=mf;
z=mm+1;
n=10;
cout << "Beta CPU Gamma CPU\n";
for(i=1; i<= n; ++i) {
timer.start();
Ib=gsl_sf_beta(z,w);
timer.stop();
t1=timer.get_click();
timer.start();
Ig=gsl_sf_gamma(z)*gsl_sf_gamma(w)/gsl_sf_gamma(w+z);
timer.stop();
t2=timer.get_click();
// cout << Ib << ' ' << Ig << endl;
cout << "Loop " << i << endl;
cout << t1 << ' ' << t2 << endl;
}
}
// Routine principale
int main() {
test_gsl();
return 0;
}
_______________________________________________
Help-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gsl