|
Boost-Commit : |
From: johnmaddock_at_[hidden]
Date: 2007-05-22 04:56:12
Author: johnmaddock
Date: 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
New Revision: 4173
URL: http://svn.boost.org/trac/boost/changeset/4173
Log:
Added performance test program.
Added:
sandbox/math_toolkit/libs/math/performance/
sandbox/math_toolkit/libs/math/performance/distributions.cpp
sandbox/math_toolkit/libs/math/performance/main.cpp
sandbox/math_toolkit/libs/math/performance/performance_measure.hpp
sandbox/math_toolkit/libs/math/performance/test_erf.cpp
sandbox/math_toolkit/libs/math/performance/test_gamma.cpp
sandbox/math_toolkit/libs/math/performance/test_ibeta.cpp
sandbox/math_toolkit/libs/math/performance/test_igamma.cpp
sandbox/math_toolkit/libs/math/performance/test_polynomial.cpp
sandbox/math_toolkit/libs/math/performance/test_reference.cpp
Added: sandbox/math_toolkit/libs/math/performance/distributions.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/distributions.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,357 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/distributions/beta.hpp>
+#include <boost/math/distributions/binomial.hpp>
+#include <boost/math/distributions/cauchy.hpp>
+#include <boost/math/distributions/chi_squared.hpp>
+#include <boost/math/distributions/exponential.hpp>
+#include <boost/math/distributions/fisher_f.hpp>
+#include <boost/math/distributions/gamma.hpp>
+#include <boost/math/distributions/lognormal.hpp>
+#include <boost/math/distributions/negative_binomial.hpp>
+#include <boost/math/distributions/normal.hpp>
+#include <boost/math/distributions/poisson.hpp>
+#include <boost/math/distributions/students_t.hpp>
+#include <boost/math/distributions/weibull.hpp>
+
+double probabilities[] = {
+ 1e-5,
+ 1e-4,
+ 1e-3,
+ 1e-2,
+ 0.05,
+ 0.1,
+ 0.2,
+ 0.3,
+ 0.4,
+ 0.5,
+ 0.6,
+ 0.7,
+ 0.8,
+ 0.9,
+ 0.95,
+ 1-1e-5,
+ 1-1e-4,
+ 1-1e-3,
+ 1-1e-2
+};
+
+int int_values[] = {
+ 1,
+ 2,
+ 3,
+ 5,
+ 10,
+ 20,
+ 50,
+ 100,
+ 1000,
+ 10000,
+ 100000
+};
+
+double real_values[] = {
+ 1e-5,
+ 1e-4,
+ 1e-2,
+ 1e-1,
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000
+};
+
+#define BOOST_MATH_DISTRIBUTION2_TEST(name, param1_table, param2_table, random_variable_table, probability_table) \
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist, name), "dist-" BOOST_STRINGIZE(name) "-cdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += cdf(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i], param2_table[j]), random_variable_table[k]);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_pdf_, name), "dist-" BOOST_STRINGIZE(name) "-pdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += pdf(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i], param2_table[j]), random_variable_table[k]);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_quant, name), "dist-" BOOST_STRINGIZE(name) "-quantile")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(probability_table)/sizeof(probability_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += quantile(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i], param2_table[j]), probability_table[k]);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }
+
+#define BOOST_MATH_DISTRIBUTION1_TEST(name, param1_table, random_variable_table, probability_table) \
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist, name), "dist-" BOOST_STRINGIZE(name) "-cdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += cdf(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i]), random_variable_table[k]);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_pdf_, name), "dist-" BOOST_STRINGIZE(name) "-pdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += pdf(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i]), random_variable_table[k]);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_quant, name), "dist-" BOOST_STRINGIZE(name) "-quantile")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(probability_table)/sizeof(probability_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += quantile(boost::math:: BOOST_JOIN(name, _distribution) <>(param1_table[i]), probability_table[k]);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }
+
+BOOST_MATH_DISTRIBUTION2_TEST(beta, probabilities, probabilities, probabilities, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(binomial, int_values, probabilities, int_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(cauchy, int_values, real_values, int_values, probabilities)
+BOOST_MATH_DISTRIBUTION1_TEST(chi_squared, int_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION1_TEST(exponential, real_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(fisher_f, int_values, int_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(gamma, real_values, real_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(lognormal, real_values, real_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(negative_binomial, int_values, probabilities, int_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(normal, real_values, real_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION1_TEST(poisson, real_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION1_TEST(students_t, int_values, real_values, probabilities)
+BOOST_MATH_DISTRIBUTION2_TEST(weibull, real_values, real_values, real_values, probabilities)
+
+#ifdef TEST_R
+
+extern "C" {
+#include "Rmath.h"
+}
+
+#define BOOST_MATH_R_DISTRIBUTION2_TEST(name, param1_table, param2_table, random_variable_table, probability_table) \
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist, name), "dist-" #name "-R-cdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_p##name (random_variable_table[k], param1_table[i], param2_table[j], 1, 0);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_pdf_, name), "dist-" #name "-R-pdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_d##name (random_variable_table[k], param1_table[i], param2_table[j], 0);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_quant, name), "dist-" #name "-R-quantile")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned b_size = sizeof(param2_table)/sizeof(param2_table[0]);\
+ unsigned c_size = sizeof(probability_table)/sizeof(probability_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned j = 0; j < b_size; ++j)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_q##name (probability_table[k], param1_table[i], param2_table[j], 1, 0);\
+ }\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * b_size * c_size);\
+ }
+
+#define BOOST_MATH_R_DISTRIBUTION1_TEST(name, param1_table, random_variable_table, probability_table) \
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist, name), "dist-" #name "-R-cdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_p##name (random_variable_table[k], param1_table[i], 1, 0);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_pdf_, name), "dist-" #name "-R-pdf")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(random_variable_table)/sizeof(random_variable_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_d##name (random_variable_table[k], param1_table[i], 0);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }\
+ BOOST_MATH_PERFORMANCE_TEST(BOOST_JOIN(dist_quant, name), "dist-" #name "-R-quantile")\
+ {\
+ double result = 0;\
+ unsigned a_size = sizeof(param1_table)/sizeof(param1_table[0]);\
+ unsigned c_size = sizeof(probability_table)/sizeof(probability_table[0]);\
+ \
+ for(unsigned i = 0; i < a_size; ++i)\
+ {\
+ for(unsigned k = 0; k < c_size; ++k)\
+ {\
+ result += Rf_q##name (probability_table[k], param1_table[i], 1, 0);\
+ }\
+ }\
+ \
+ consume_result(result);\
+ set_call_count(a_size * c_size);\
+ }
+//
+// The R lib actually gives these non-obvious names that we can't deduce
+// in our own macro code, so create unline forwarders and let R's own
+// macros have control over dispatch to the right algorithm:
+//
+inline double Rf_dnorm(double x, double mu, double sigma, int give_log)
+{
+ return dnorm(x, mu, sigma, give_log);
+}
+
+inline double Rf_pnorm(double x, double mu, double sigma, int lower_tail, int give_log)
+{
+ return pnorm(x, mu, sigma, lower_tail, give_log);
+}
+
+inline double Rf_qnorm(double p, double mu, double sigma, int lower_tail, int log_p)
+{
+ return qnorm(p, mu, sigma, lower_tail, log_p);
+}
+
+BOOST_MATH_R_DISTRIBUTION2_TEST(beta, probabilities, probabilities, probabilities, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(binom, int_values, probabilities, int_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(cauchy, int_values, real_values, int_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION1_TEST(chisq, int_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION1_TEST(exp, real_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(f, int_values, int_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(gamma, real_values, real_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(lnorm, real_values, real_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(nbinom, int_values, probabilities, int_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(norm, real_values, real_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION1_TEST(pois, real_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION1_TEST(t, int_values, real_values, probabilities)
+BOOST_MATH_R_DISTRIBUTION2_TEST(weibull, real_values, real_values, real_values, probabilities)
+
+#endif
+
Added: sandbox/math_toolkit/libs/math/performance/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/main.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,164 @@
+
+#include <map>
+#include <set>
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <cstring>
+#include "performance_measure.hpp"
+
+extern void reference_evaluate();
+/*
+extern void polynomial_evaluate();
+extern void polynomial_mixed_evaluate();
+extern void rational_evaluate();
+extern void rational_mixed_evaluate();
+extern void gamma_evaluate();
+extern void lgamma_evaluate();
+extern void erf_evaluate();
+extern void igamma_evaluate();
+extern void igamma_inv_evaluate();
+extern void ibeta_evaluate();
+extern void ibeta_inv_evaluate();
+
+
+
+test_info info[] = {
+ { "polynomial", &polynomial_evaluate },
+ { "polynomial_mixed", &polynomial_mixed_evaluate },
+ { "rational", &rational_evaluate },
+ { "rational_mixed", &rational_mixed_evaluate },
+ { "gamma", &gamma_evaluate },
+ { "lgamma", &lgamma_evaluate },
+ { "erf", &erf_evaluate },
+ { "igamma_inv", &igamma_inv_evaluate },
+ { "igamma", &igamma_evaluate },
+ { "ibeta_inv", &ibeta_inv_evaluate },
+ { "ibeta", &ibeta_evaluate },
+};
+*/
+
+std::map<std::string, double> times;
+std::set<test_info> tests;
+double total = 0;
+int call_count = 0;
+
+std::set<test_info>& all_tests()
+{
+ static std::set<test_info> i;
+ return i;
+}
+
+void add_new_test(test_info i)
+{
+ all_tests().insert(i);
+}
+
+void set_call_count(int i)
+{
+ call_count = i;
+}
+
+void show_help()
+{
+ std::cout << "Specify on the command line which functions to test.\n"
+ "Available options are:\n";
+ std::set<test_info>::const_iterator i(all_tests().begin()), j(all_tests().end());
+ while(i != j)
+ {
+ std::cout << " --" << (*i).name << std::endl;
+ ++i;
+ }
+ std::cout << "Or use --all to test everything." << std::endl;
+}
+
+void run_tests()
+{
+ // Get time for empty proceedure:
+ double reference_time = performance_measure(reference_evaluate);
+
+ std::set<test_info>::const_iterator i, j;
+ for(i = tests.begin(), j = tests.end(); i != j; ++i)
+ {
+ set_call_count(1);
+ std::cout << "Testing " << std::left << std::setw(40) << i->name << std::flush;
+ double time = performance_measure(i->proc) - reference_time;
+ time /= call_count;
+ std::cout << std::setprecision(3) << std::scientific << time << std::endl;
+ }
+}
+
+int main(int argc, const char** argv)
+{
+ try{
+
+ if(argc >= 2)
+ {
+ for(int i = 1; i < argc; ++i)
+ {
+ if(std::strcmp(argv[i], "--help") == 0)
+ {
+ show_help();
+ }
+ else if(std::strcmp(argv[i], "--all") == 0)
+ {
+ std::set<test_info>::const_iterator a(all_tests().begin()), b(all_tests().end());
+ while(a != b)
+ {
+ tests.insert(*a);
+ ++a;
+ }
+ }
+ else
+ {
+ bool found = false;
+ if((argv[i][0] == '-') && (argv[i][1] == '-'))
+ {
+ std::set<test_info>::const_iterator a(all_tests().begin()), b(all_tests().end());
+ while(a != b)
+ {
+ if(std::strcmp(argv[i] + 2, (*a).name) == 0)
+ {
+ found = true;
+ tests.insert(*a);
+ break;
+ }
+ ++a;
+ }
+ }
+ if(!found)
+ {
+ std::cerr << "Unknown option: " << argv[i] << std::endl;
+ return 1;
+ }
+ }
+ }
+ }
+ else
+ {
+ show_help();
+ }
+ run_tests();
+ //
+ // This is just to confuse the optimisers:
+ //
+ if(argc == 100000)
+ {
+ std::cerr << total << std::endl;
+ }
+
+ }
+ catch(const std::exception& e)
+ {
+ std::cerr << e.what() << std::endl;
+ }
+
+ return 0;
+}
+
+void consume_result(double x)
+{
+ // Do nothing proceedure, don't let whole program optimisation
+ // optimise this away - doing so may cause false readings....
+ total += x;
+}
Added: sandbox/math_toolkit/libs/math/performance/performance_measure.hpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/performance_measure.hpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,81 @@
+
+#ifndef BOOST_MATH_PERFORMANCE_MEASURE_HPP
+#define BOOST_MATH_PERFORMANCE_MEASURE_HPP
+
+#include <boost/config.hpp>
+#include <boost/timer.hpp>
+#include <cstring>
+
+template <class F>
+double performance_measure(F f)
+{
+ unsigned count = 1;
+ double time, result;
+ //
+ // Begin by figuring out how many times to repeat
+ // the function call in order to get a measureable time:
+ //
+ do
+ {
+ boost::timer t;
+ for(unsigned i = 0; i < count; ++i)
+ f();
+ time = t.elapsed();
+ count *= 2;
+ t.restart();
+ }while(time < 0.5);
+
+ count /= 2;
+ result = time;
+ //
+ // Now repeat the measurement over and over
+ // and take the shortest measured time as the
+ // result, generally speaking this gives us
+ // consistent results:
+ //
+ for(unsigned i = 0; i < 10u;++i)
+ {
+ boost::timer t;
+ for(unsigned i = 0; i < count; ++i)
+ f();
+ time = t.elapsed();
+ if(time < result)
+ result = time;
+ t.restart();
+ }
+ return result / count;
+}
+
+struct test_info
+{
+ test_info(const char* n, void (*p)());
+ const char* name;
+ void (*proc)();
+};
+
+inline bool operator < (const test_info& a, const test_info& b)
+{
+ return std::strcmp(a.name, b.name) < 0;
+}
+
+extern void consume_result(double);
+extern void set_call_count(int i);
+extern void add_new_test(test_info i);
+
+inline test_info::test_info(const char* n, void (*p)())
+{
+ name = n;
+ proc = p;
+ add_new_test(*this);
+}
+
+#define BOOST_MATH_PERFORMANCE_TEST(name, string) \
+ void BOOST_JOIN(name, __LINE__) ();\
+ namespace{\
+ test_info BOOST_JOIN(BOOST_JOIN(name, _init), __LINE__)(string, BOOST_JOIN(name, __LINE__));\
+ }\
+ void BOOST_JOIN(name, __LINE__) ()
+
+
+
+#endif // BOOST_MATH_PERFORMANCE_MEASURE_HPP
Added: sandbox/math_toolkit/libs/math/performance/test_erf.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_erf.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,48 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/special_functions/gamma.hpp>
+#include <boost/array.hpp>
+
+#define T double
+#include "../test/erf_data.ipp"
+#include "../test/erf_large_data.ipp"
+#include "../test/erf_small_data.ipp"
+
+template <std::size_t N>
+double erf_evaluate2(const boost::array<boost::array<T, 3>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::erf(data[i][0]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(erf_test, "erf")
+{
+ double result = erf_evaluate2(erf_data);
+ result += erf_evaluate2(erf_large_data);
+ result += erf_evaluate2(erf_small_data);
+
+ consume_result(result);
+ set_call_count((sizeof(erf_data) + sizeof(erf_large_data) + sizeof(erf_small_data)) / sizeof(erf_data[0]));
+}
+
+template <std::size_t N>
+double erf_inv_evaluate2(const boost::array<boost::array<T, 3>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::erf_inv(data[i][1]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(erf_inv_test, "erf_inv")
+{
+ double result = erf_inv_evaluate2(erf_data);
+ result += erf_inv_evaluate2(erf_large_data);
+ result += erf_inv_evaluate2(erf_small_data);
+
+ consume_result(result);
+ set_call_count((sizeof(erf_data) + sizeof(erf_large_data) + sizeof(erf_small_data)) / sizeof(erf_data[0]));
+}
\ No newline at end of file
Added: sandbox/math_toolkit/libs/math/performance/test_gamma.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_gamma.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,64 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/special_functions/gamma.hpp>
+#include <boost/array.hpp>
+
+#define T double
+#include "../test/test_gamma_data.ipp"
+
+template <std::size_t N>
+double gamma_evaluate2(const boost::array<boost::array<T, 3>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::tgamma(data[i][0]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(gamma_test, "gamma")
+{
+ double result = gamma_evaluate2(factorials);
+ result += gamma_evaluate2(near_1);
+ result += gamma_evaluate2(near_2);
+ result += gamma_evaluate2(near_0);
+ result += gamma_evaluate2(near_m10);
+ result += gamma_evaluate2(near_m55);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(factorials)
+ + sizeof(near_1)
+ + sizeof(near_2)
+ + sizeof(near_0)
+ + sizeof(near_m10)
+ + sizeof(near_m55)) / sizeof(factorials[0]));
+}
+
+template <std::size_t N>
+double lgamma_evaluate2(const boost::array<boost::array<T, 3>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::lgamma(data[i][0]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(lgamma_test, "lgamma")
+{
+ double result = lgamma_evaluate2(factorials);
+ result += lgamma_evaluate2(near_1);
+ result += lgamma_evaluate2(near_2);
+ result += lgamma_evaluate2(near_0);
+ result += lgamma_evaluate2(near_m10);
+ result += lgamma_evaluate2(near_m55);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(factorials)
+ + sizeof(near_1)
+ + sizeof(near_2)
+ + sizeof(near_0)
+ + sizeof(near_m10)
+ + sizeof(near_m55)) / sizeof(factorials[0]));
+}
Added: sandbox/math_toolkit/libs/math/performance/test_ibeta.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_ibeta.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,59 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/special_functions/beta.hpp>
+#include <boost/array.hpp>
+
+#define T double
+#include "../test/ibeta_data.ipp"
+#include "../test/ibeta_int_data.ipp"
+#include "../test/ibeta_large_data.ipp"
+#include "../test/ibeta_small_data.ipp"
+
+template <std::size_t N>
+double ibeta_evaluate2(const boost::array<boost::array<T, 7>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::ibeta(data[i][0], data[i][1], data[i][2]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(ibeta_test, "ibeta")
+{
+ double result = ibeta_evaluate2(ibeta_data);
+ result += ibeta_evaluate2(ibeta_int_data);
+ result += ibeta_evaluate2(ibeta_large_data);
+ result += ibeta_evaluate2(ibeta_small_data);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(ibeta_data)
+ + sizeof(ibeta_int_data)
+ + sizeof(ibeta_large_data)
+ + sizeof(ibeta_small_data)) / sizeof(ibeta_data[0]));
+}
+
+template <std::size_t N>
+double ibeta_inv_evaluate2(const boost::array<boost::array<T, 7>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::ibeta_inv(data[i][0], data[i][1], data[i][5]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(ibeta_inv_test, "ibeta_inv")
+{
+ double result = ibeta_inv_evaluate2(ibeta_data);
+ result += ibeta_inv_evaluate2(ibeta_int_data);
+ result += ibeta_inv_evaluate2(ibeta_large_data);
+ result += ibeta_inv_evaluate2(ibeta_small_data);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(ibeta_data)
+ + sizeof(ibeta_int_data)
+ + sizeof(ibeta_large_data)
+ + sizeof(ibeta_small_data)) / sizeof(ibeta_data[0]));
+}
Added: sandbox/math_toolkit/libs/math/performance/test_igamma.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_igamma.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,59 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/special_functions/gamma.hpp>
+#include <boost/array.hpp>
+
+#define T double
+#include "../test/igamma_big_data.ipp"
+#include "../test/igamma_int_data.ipp"
+#include "../test/igamma_med_data.ipp"
+#include "../test/igamma_small_data.ipp"
+
+template <std::size_t N>
+double igamma_evaluate2(const boost::array<boost::array<T, 6>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::gamma_p(data[i][0], data[i][1]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(igamma_test, "igamma")
+{
+ double result = igamma_evaluate2(igamma_big_data);
+ result += igamma_evaluate2(igamma_int_data);
+ result += igamma_evaluate2(igamma_med_data);
+ result += igamma_evaluate2(igamma_small_data);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(igamma_big_data)
+ + sizeof(igamma_int_data)
+ + sizeof(igamma_med_data)
+ + sizeof(igamma_small_data)) / sizeof(igamma_big_data[0]));
+}
+
+template <std::size_t N>
+double igamma_inv_evaluate2(const boost::array<boost::array<T, 6>, N>& data)
+{
+ double result = 0;
+ for(unsigned i = 0; i < N; ++i)
+ result += boost::math::gamma_p_inv(data[i][0], data[i][5]);
+ return result;
+}
+
+BOOST_MATH_PERFORMANCE_TEST(igamma_inv_test, "igamma_inv")
+{
+ double result = igamma_inv_evaluate2(igamma_big_data);
+ result += igamma_inv_evaluate2(igamma_int_data);
+ result += igamma_inv_evaluate2(igamma_med_data);
+ result += igamma_inv_evaluate2(igamma_small_data);
+
+ consume_result(result);
+ set_call_count(
+ (sizeof(igamma_big_data)
+ + sizeof(igamma_int_data)
+ + sizeof(igamma_med_data)
+ + sizeof(igamma_small_data)) / sizeof(igamma_big_data[0]));
+}
Added: sandbox/math_toolkit/libs/math/performance/test_polynomial.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_polynomial.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,166 @@
+
+#include "performance_measure.hpp"
+
+#include <boost/math/tools/rational.hpp>
+#include <boost/cstdint.hpp>
+
+BOOST_MATH_PERFORMANCE_TEST(poly_test, "polynomial")
+{
+ typedef double T;
+ static const T num[13] = {
+ static_cast<T>(56906521.91347156388090791033559122686859L),
+ static_cast<T>(103794043.1163445451906271053616070238554L),
+ static_cast<T>(86363131.28813859145546927288977868422342L),
+ static_cast<T>(43338889.32467613834773723740590533316085L),
+ static_cast<T>(14605578.08768506808414169982791359218571L),
+ static_cast<T>(3481712.15498064590882071018964774556468L),
+ static_cast<T>(601859.6171681098786670226533699352302507L),
+ static_cast<T>(75999.29304014542649875303443598909137092L),
+ static_cast<T>(6955.999602515376140356310115515198987526L),
+ static_cast<T>(449.9445569063168119446858607650988409623L),
+ static_cast<T>(19.51992788247617482847860966235652136208L),
+ static_cast<T>(0.5098416655656676188125178644804694509993L),
+ static_cast<T>(0.006061842346248906525783753964555936883222L)
+ };
+ static const double denom[13] = {
+ static_cast<boost::uint32_t>(0u),
+ static_cast<boost::uint32_t>(39916800u),
+ static_cast<boost::uint32_t>(120543840u),
+ static_cast<boost::uint32_t>(150917976u),
+ static_cast<boost::uint32_t>(105258076u),
+ static_cast<boost::uint32_t>(45995730u),
+ static_cast<boost::uint32_t>(13339535u),
+ static_cast<boost::uint32_t>(2637558u),
+ static_cast<boost::uint32_t>(357423u),
+ static_cast<boost::uint32_t>(32670u),
+ static_cast<boost::uint32_t>(1925u),
+ static_cast<boost::uint32_t>(66u),
+ static_cast<boost::uint32_t>(1u)
+ };
+ double result = 0;
+ for(double i = 1; i < 100; i += 0.5)
+ result += boost::math::tools::evaluate_polynomial(num, i) / boost::math::tools::evaluate_polynomial(denom, i);
+ consume_result(result);
+ set_call_count(200);
+}
+
+BOOST_MATH_PERFORMANCE_TEST(poly_mixed_test, "polynomial-mixed")
+{
+ typedef double T;
+ static const T num[13] = {
+ static_cast<T>(56906521.91347156388090791033559122686859L),
+ static_cast<T>(103794043.1163445451906271053616070238554L),
+ static_cast<T>(86363131.28813859145546927288977868422342L),
+ static_cast<T>(43338889.32467613834773723740590533316085L),
+ static_cast<T>(14605578.08768506808414169982791359218571L),
+ static_cast<T>(3481712.15498064590882071018964774556468L),
+ static_cast<T>(601859.6171681098786670226533699352302507L),
+ static_cast<T>(75999.29304014542649875303443598909137092L),
+ static_cast<T>(6955.999602515376140356310115515198987526L),
+ static_cast<T>(449.9445569063168119446858607650988409623L),
+ static_cast<T>(19.51992788247617482847860966235652136208L),
+ static_cast<T>(0.5098416655656676188125178644804694509993L),
+ static_cast<T>(0.006061842346248906525783753964555936883222L)
+ };
+ static const boost::uint32_t denom[13] = {
+ static_cast<boost::uint32_t>(0u),
+ static_cast<boost::uint32_t>(39916800u),
+ static_cast<boost::uint32_t>(120543840u),
+ static_cast<boost::uint32_t>(150917976u),
+ static_cast<boost::uint32_t>(105258076u),
+ static_cast<boost::uint32_t>(45995730u),
+ static_cast<boost::uint32_t>(13339535u),
+ static_cast<boost::uint32_t>(2637558u),
+ static_cast<boost::uint32_t>(357423u),
+ static_cast<boost::uint32_t>(32670u),
+ static_cast<boost::uint32_t>(1925u),
+ static_cast<boost::uint32_t>(66u),
+ static_cast<boost::uint32_t>(1u)
+ };
+ double result = 0;
+ for(double i = 1; i < 100; i += 0.5)
+ result += boost::math::tools::evaluate_polynomial(num, i) / boost::math::tools::evaluate_polynomial(denom, i);
+ consume_result(result);
+ set_call_count(200);
+}
+
+BOOST_MATH_PERFORMANCE_TEST(rat_test, "rational")
+{
+ typedef double T;
+ static const T num[13] = {
+ static_cast<T>(56906521.91347156388090791033559122686859L),
+ static_cast<T>(103794043.1163445451906271053616070238554L),
+ static_cast<T>(86363131.28813859145546927288977868422342L),
+ static_cast<T>(43338889.32467613834773723740590533316085L),
+ static_cast<T>(14605578.08768506808414169982791359218571L),
+ static_cast<T>(3481712.15498064590882071018964774556468L),
+ static_cast<T>(601859.6171681098786670226533699352302507L),
+ static_cast<T>(75999.29304014542649875303443598909137092L),
+ static_cast<T>(6955.999602515376140356310115515198987526L),
+ static_cast<T>(449.9445569063168119446858607650988409623L),
+ static_cast<T>(19.51992788247617482847860966235652136208L),
+ static_cast<T>(0.5098416655656676188125178644804694509993L),
+ static_cast<T>(0.006061842346248906525783753964555936883222L)
+ };
+ static const double denom[13] = {
+ static_cast<boost::uint32_t>(0u),
+ static_cast<boost::uint32_t>(39916800u),
+ static_cast<boost::uint32_t>(120543840u),
+ static_cast<boost::uint32_t>(150917976u),
+ static_cast<boost::uint32_t>(105258076u),
+ static_cast<boost::uint32_t>(45995730u),
+ static_cast<boost::uint32_t>(13339535u),
+ static_cast<boost::uint32_t>(2637558u),
+ static_cast<boost::uint32_t>(357423u),
+ static_cast<boost::uint32_t>(32670u),
+ static_cast<boost::uint32_t>(1925u),
+ static_cast<boost::uint32_t>(66u),
+ static_cast<boost::uint32_t>(1u)
+ };
+ double result = 0;
+ for(double i = 1; i < 100; i += 0.5)
+ result += boost::math::tools::evaluate_rational(num, denom, i);
+ consume_result(result);
+ set_call_count(100);
+}
+
+BOOST_MATH_PERFORMANCE_TEST(rat_mixed_test, "rational-mixed")
+{
+ typedef double T;
+ static const T num[13] = {
+ static_cast<T>(56906521.91347156388090791033559122686859L),
+ static_cast<T>(103794043.1163445451906271053616070238554L),
+ static_cast<T>(86363131.28813859145546927288977868422342L),
+ static_cast<T>(43338889.32467613834773723740590533316085L),
+ static_cast<T>(14605578.08768506808414169982791359218571L),
+ static_cast<T>(3481712.15498064590882071018964774556468L),
+ static_cast<T>(601859.6171681098786670226533699352302507L),
+ static_cast<T>(75999.29304014542649875303443598909137092L),
+ static_cast<T>(6955.999602515376140356310115515198987526L),
+ static_cast<T>(449.9445569063168119446858607650988409623L),
+ static_cast<T>(19.51992788247617482847860966235652136208L),
+ static_cast<T>(0.5098416655656676188125178644804694509993L),
+ static_cast<T>(0.006061842346248906525783753964555936883222L)
+ };
+ static const boost::uint32_t denom[13] = {
+ static_cast<boost::uint32_t>(0u),
+ static_cast<boost::uint32_t>(39916800u),
+ static_cast<boost::uint32_t>(120543840u),
+ static_cast<boost::uint32_t>(150917976u),
+ static_cast<boost::uint32_t>(105258076u),
+ static_cast<boost::uint32_t>(45995730u),
+ static_cast<boost::uint32_t>(13339535u),
+ static_cast<boost::uint32_t>(2637558u),
+ static_cast<boost::uint32_t>(357423u),
+ static_cast<boost::uint32_t>(32670u),
+ static_cast<boost::uint32_t>(1925u),
+ static_cast<boost::uint32_t>(66u),
+ static_cast<boost::uint32_t>(1u)
+ };
+ double result = 0;
+ for(double i = 1; i < 100; i += 0.5)
+ result += boost::math::tools::evaluate_rational(num, denom, i);
+ consume_result(result);
+ set_call_count(100);
+}
+
Added: sandbox/math_toolkit/libs/math/performance/test_reference.cpp
==============================================================================
--- (empty file)
+++ sandbox/math_toolkit/libs/math/performance/test_reference.cpp 2007-05-22 04:56:11 EDT (Tue, 22 May 2007)
@@ -0,0 +1,10 @@
+
+#include "performance_measure.hpp"
+
+void reference_evaluate()
+{
+ consume_result(2.0);
+ set_call_count(1);
+}
+
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk