|  | 
|  | 1 | +/* | 
|  | 2 | +Contains the performance tests for the logarithm implementation. | 
|  | 3 | + */ | 
|  | 4 | +#include <chrono> | 
|  | 5 | +#include <limits> | 
|  | 6 | +#include <iomanip> | 
|  | 7 | +#include <iostream> | 
|  | 8 | +#include <string> | 
|  | 9 | +#include <vector> | 
|  | 10 | + | 
|  | 11 | +#include <boost/math/constants/constants.hpp> | 
|  | 12 | +#include <boost/multiprecision/cpp_bin_float.hpp> | 
|  | 13 | +#include <boost/multiprecision/cpp_dec_float.hpp> | 
|  | 14 | +#include <boost/multiprecision/cpp_int.hpp> | 
|  | 15 | +#include <random> | 
|  | 16 | + | 
|  | 17 | +#include "boost_gsoc_benchmark_utils.h" | 
|  | 18 | + | 
|  | 19 | +template <typename Generator> | 
|  | 20 | +std::string generateRandomNumber(size_t digits, Generator& gen) | 
|  | 21 | +{ | 
|  | 22 | +   std::uniform_int_distribution<int> uniform_digit(0, 10); | 
|  | 23 | +   std::uniform_int_distribution<size_t> uniform_point(1, digits); | 
|  | 24 | +   std::string                        str; | 
|  | 25 | +   str += std::to_string(uniform_digit(gen) % 9 + 1); | 
|  | 26 | +   size_t point = uniform_point(gen); | 
|  | 27 | +   for (size_t i = 1; i < digits; ++i) | 
|  | 28 | +   { | 
|  | 29 | +      str += std::to_string(uniform_digit(gen)); | 
|  | 30 | +      if (i == point) | 
|  | 31 | +         str += '.'; | 
|  | 32 | +   } | 
|  | 33 | +   return str; | 
|  | 34 | +} | 
|  | 35 | + | 
|  | 36 | +template <typename T> | 
|  | 37 | +void run_time_experiments(size_t cur_digits) | 
|  | 38 | +{ | 
|  | 39 | +    size_t                     reps = 20; | 
|  | 40 | +    std::default_random_engine generator(42); | 
|  | 41 | +    int                        total = 0; | 
|  | 42 | +    boost_gsoc2020::aggregator_type aggregator; | 
|  | 43 | +    for (size_t rep = 0; rep < reps; ++rep) | 
|  | 44 | +    { | 
|  | 45 | +        T                              val(generateRandomNumber(cur_digits, generator)); | 
|  | 46 | +        boost_gsoc2020::stopwatch_type stopwatch; | 
|  | 47 | +        stopwatch.reset(); | 
|  | 48 | +        T ans = log(val); | 
|  | 49 | +        total += !ans.is_zero(); | 
|  | 50 | +        auto time = stopwatch.elapsed().count(); | 
|  | 51 | +        aggregator.addMeasurement(time); | 
|  | 52 | +    } | 
|  | 53 | +    double mean         = aggregator.getMean() / 1000000000.0; | 
|  | 54 | +    double st_deviation = sqrt(aggregator.getVariance()) / 1000000000.0; | 
|  | 55 | +    std::cout << "(" << cur_digits << ", " << mean << ") +- (" | 
|  | 56 | +              << st_deviation << ", " << 1.96 * st_deviation << ")" << std::endl; | 
|  | 57 | +} | 
|  | 58 | + | 
|  | 59 | +template<size_t Digits> | 
|  | 60 | +void run_time_experiment_for_cpp_bin_float() { | 
|  | 61 | +   run_time_experiments<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<Digits> > >(Digits); | 
|  | 62 | +} | 
|  | 63 | + | 
|  | 64 | +template <size_t Digits> | 
|  | 65 | +void run_time_experiment_for_cpp_dec_float() | 
|  | 66 | +{ | 
|  | 67 | +   run_time_experiments<boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<Digits> > >(Digits); | 
|  | 68 | +} | 
|  | 69 | + | 
|  | 70 | +int main() | 
|  | 71 | +{ | 
|  | 72 | +    | 
|  | 73 | +   std::cout << "==== Running tests for cpp_bin_float: ====" << std::endl; | 
|  | 74 | +   run_time_experiment_for_cpp_bin_float<1000>(); | 
|  | 75 | +   run_time_experiment_for_cpp_bin_float<1500>(); | 
|  | 76 | +   run_time_experiment_for_cpp_bin_float<2000>(); | 
|  | 77 | +   run_time_experiment_for_cpp_bin_float<2500>(); | 
|  | 78 | +   run_time_experiment_for_cpp_bin_float<3000>(); | 
|  | 79 | +   run_time_experiment_for_cpp_bin_float<3500>(); | 
|  | 80 | +   run_time_experiment_for_cpp_bin_float<4000>(); | 
|  | 81 | +   run_time_experiment_for_cpp_bin_float<4500>(); | 
|  | 82 | +   run_time_experiment_for_cpp_bin_float<5000>(); | 
|  | 83 | +   run_time_experiment_for_cpp_bin_float<5500>(); | 
|  | 84 | +   run_time_experiment_for_cpp_bin_float<6000>(); | 
|  | 85 | +   run_time_experiment_for_cpp_bin_float<6500>(); | 
|  | 86 | +   run_time_experiment_for_cpp_bin_float<7000>(); | 
|  | 87 | +   run_time_experiment_for_cpp_bin_float<7500>(); | 
|  | 88 | +   run_time_experiment_for_cpp_bin_float<8000>(); | 
|  | 89 | +   run_time_experiment_for_cpp_bin_float<8500>(); | 
|  | 90 | +   run_time_experiment_for_cpp_bin_float<9000>(); | 
|  | 91 | +   run_time_experiment_for_cpp_bin_float<9500>(); | 
|  | 92 | +   run_time_experiment_for_cpp_bin_float<10000>(); | 
|  | 93 | + | 
|  | 94 | +   /* std::cout << "==== Running tests for cpp_dec_float: ====" << std::endl; | 
|  | 95 | +   run_time_experiment_for_cpp_dec_float<1000>(); | 
|  | 96 | +   run_time_experiment_for_cpp_dec_float<1500>(); | 
|  | 97 | +   run_time_experiment_for_cpp_dec_float<2000>(); | 
|  | 98 | +   run_time_experiment_for_cpp_dec_float<2500>(); | 
|  | 99 | +   run_time_experiment_for_cpp_dec_float<3000>(); | 
|  | 100 | +   run_time_experiment_for_cpp_dec_float<3500>(); | 
|  | 101 | +   run_time_experiment_for_cpp_dec_float<4000>(); | 
|  | 102 | +   run_time_experiment_for_cpp_dec_float<4500>(); | 
|  | 103 | +   run_time_experiment_for_cpp_dec_float<5000>(); | 
|  | 104 | +   run_time_experiment_for_cpp_dec_float<5500>(); | 
|  | 105 | +   run_time_experiment_for_cpp_dec_float<6000>(); | 
|  | 106 | +   run_time_experiment_for_cpp_dec_float<6500>(); | 
|  | 107 | +   run_time_experiment_for_cpp_dec_float<7000>(); | 
|  | 108 | +   run_time_experiment_for_cpp_dec_float<7500>(); | 
|  | 109 | +   run_time_experiment_for_cpp_dec_float<8000>(); | 
|  | 110 | +   run_time_experiment_for_cpp_dec_float<8500>(); | 
|  | 111 | +   run_time_experiment_for_cpp_dec_float<9000>(); | 
|  | 112 | +   run_time_experiment_for_cpp_dec_float<9500>(); | 
|  | 113 | +   run_time_experiment_for_cpp_dec_float<10000>(); | 
|  | 114 | +   */ | 
|  | 115 | +   return 0; | 
|  | 116 | +} | 
0 commit comments