]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/performance/sf_performance.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / multiprecision / performance / sf_performance.cpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////
2// Copyright 2011 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
92f5a8d4 4// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7c673cae
FG
5
6#include "sf_performance.hpp"
7
f67539c2
TL
8boost::atomic<unsigned> allocation_count(0);
9std::map<std::string, std::map<std::string, std::pair<double, unsigned> > > result_table;
7c673cae 10
92f5a8d4
TL
11void* (*alloc_func_ptr)(size_t);
12void* (*realloc_func_ptr)(void*, size_t, size_t);
13void (*free_func_ptr)(void*, size_t);
7c673cae 14
92f5a8d4 15void* alloc_func(size_t n)
7c673cae
FG
16{
17 ++allocation_count;
18 return (*alloc_func_ptr)(n);
19}
20
92f5a8d4 21void free_func(void* p, size_t n)
7c673cae
FG
22{
23 (*free_func_ptr)(p, n);
24}
25
92f5a8d4 26void* realloc_func(void* p, size_t old, size_t n)
7c673cae
FG
27{
28 ++allocation_count;
29 return (*realloc_func_ptr)(p, old, n);
30}
31
f67539c2
TL
32void* operator new(std::size_t count)
33{
34 ++allocation_count;
35 return std::malloc(count);
36}
37
38void* operator new[](std::size_t count)
39{
40 ++allocation_count;
41 return std::malloc(count);
42}
43
44void operator delete(void* ptr)noexcept
45{
46 std::free(ptr);
47}
48void operator delete[](void* ptr) noexcept
49{
50 std::free(ptr);
51}
52
53void 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
7c673cae
FG
74int 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
f67539c2
TL
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();
7c673cae
FG
92 bessel_tests();
93 poly_tests();
94 nct_tests();
f67539c2
TL
95
96 print_quickbook_tables();
7c673cae 97}