• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////
2 //  Copyright 2011 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5 
6 #include "sf_performance.hpp"
7 
8 boost::atomic<unsigned>                                                     allocation_count(0);
9 std::map<std::string, std::map<std::string, std::pair<double, unsigned> > > result_table;
10 
11 void* (*alloc_func_ptr)(size_t);
12 void* (*realloc_func_ptr)(void*, size_t, size_t);
13 void (*free_func_ptr)(void*, size_t);
14 
alloc_func(size_t n)15 void* alloc_func(size_t n)
16 {
17    ++allocation_count;
18    return (*alloc_func_ptr)(n);
19 }
20 
free_func(void * p,size_t n)21 void free_func(void* p, size_t n)
22 {
23    (*free_func_ptr)(p, n);
24 }
25 
realloc_func(void * p,size_t old,size_t n)26 void* realloc_func(void* p, size_t old, size_t n)
27 {
28    ++allocation_count;
29    return (*realloc_func_ptr)(p, old, n);
30 }
31 
operator new(std::size_t count)32 void* operator new(std::size_t count)
33 {
34    ++allocation_count;
35    return std::malloc(count);
36 }
37 
operator new[](std::size_t count)38 void* operator new[](std::size_t count)
39 {
40    ++allocation_count;
41    return std::malloc(count);
42 }
43 
operator delete(void * ptr)44 void operator delete(void* ptr)noexcept
45 {
46    std::free(ptr);
47 }
operator delete[](void * ptr)48 void operator delete[](void* ptr) noexcept
49 {
50    std::free(ptr);
51 }
52 
print_quickbook_tables()53 void print_quickbook_tables()
54 {
55    for (auto i = result_table.begin(); i != result_table.end(); ++i)
56    {
57       std::cout << "[table " << i->first << "\n";
58       std::cout << "[[Type][Time][# Allocations]]\n";
59       double min_time = (std::numeric_limits<double>::max)();
60       for (auto j = i->second.begin(); j != i->second.end(); ++j)
61       {
62          if (j->second.first < min_time)
63             min_time = j->second.first;
64       }
65       for (auto j = i->second.begin(); j != i->second.end(); ++j)
66       {
67          double t = j->second.first;
68          std::cout << "[[" << j->first << "][" << t / min_time << " (" << t << "s)][" << j->second.second << "]]\n";
69       }
70       std::cout << "]\n\n";
71    }
72 }
73 
main()74 int main()
75 {
76    using namespace boost::multiprecision;
77 
78 #if defined(TEST_MPFR) || defined(TEST_MPFR_CLASS) || defined(TEST_MPREAL) || defined(TEST_MPF)
79    mp_get_memory_functions(&alloc_func_ptr, &realloc_func_ptr, &free_func_ptr);
80    mp_set_memory_functions(&alloc_func, &realloc_func, &free_func);
81 #endif
82 
83    basic_tests_1();
84    basic_tests_2();
85    basic_tests_3();
86    basic_tests_4();
87    basic_tests_5();
88    basic_tests_6();
89    basic_tests_7();
90    basic_tests_8();
91    basic_tests_9();
92    bessel_tests();
93    poly_tests();
94    nct_tests();
95 
96    print_quickbook_tables();
97 }
98