]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/dynamic_bitset/example/timing_tests.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / dynamic_bitset / example / timing_tests.cpp
CommitLineData
7c673cae
FG
1// -----------------------------------------------------------
2//
3// Copyright (c) 2003-2004 Gennaro Prota
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// -----------------------------------------------------------
10
11// boost::dynamic_bitset timing tests
12//
13// NOTE:
14// ~~~~~
15// This is a preliminary, incomplete version.
16//
17// If you are interested in having more benchmarks please make a
18// request on the boost list, which could encourage me to continue
19// this work.
20
21// Also, if you use boost::dynamic_bitset on a platform where
22// CHAR_BIT >= 9 I suggest experimenting with the size of the count
23// table in detail/dynamic_bitset.hpp and report any interesting
24// discovery on the list as well.
25
26// You might also want to try both counting methods (by_bytes vs.
27// by_blocks) to see if the one that is selected automatically is
28// actually the fastest on your system.
29
30//
31//
32// -----------------------------------------------------------------------//
33
34
35#include "boost/config.hpp"
36
37#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)
38 // for pre 3.0 versions of libstdc++
39# define BOOST_OLD_IOSTREAMS
40#endif
41// ------------------------------------------------- //
42
43#include <typeinfo>
44#include <iostream>
45#if !defined(BOOST_OLD_IOSTREAMS)
46# include <ostream>
47#endif
48
49
50#include "boost/cstdlib.hpp"
51#include "boost/version.hpp"
92f5a8d4 52#include "boost/timer/timer.hpp"
7c673cae
FG
53#include "boost/dynamic_bitset.hpp"
54
55
56namespace {
57
58 // the m_ prefixes, below, are mainly to avoid problems with g++:
59 // see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html
60 //
61 class boost_version {
62 int m_major;
63 int m_minor;
64 int m_subminor;
65
66 public:
67 boost_version(unsigned long v = BOOST_VERSION):
68 m_major(v / 100000), m_minor(v / 100 % 1000), m_subminor(v % 100) {}
69
70 friend std::ostream & operator<<(std::ostream &, const boost_version &);
71 };
72
73
74 // give up using basic_ostream, to avoid headaches with old libraries
75 std::ostream& operator<<(std::ostream& os, const boost_version & v) {
76 return os << v.m_major << '.' << v.m_minor << '.' << v.m_subminor;
77 }
78
79}
80
81
82void prologue()
83{
84 std::cout << '\n';
85 std::cout << "Compiler: " << BOOST_COMPILER << '\n';
86 std::cout << "Std lib : " << BOOST_STDLIB << '\n';
87 std::cout << "Boost v.: " << boost_version() << '\n';
88
89 std::cout << '\n';
90}
91
92
93
94template <typename T>
95void timing_test(T* = 0) // dummy parameter to workaround VC6
96{
92f5a8d4 97#ifndef BOOST_NO_STRESS_TEST
7c673cae 98 const unsigned long num = 30 * 100000;
92f5a8d4
TL
99#else
100 const unsigned long num = 30 * 1000;
101#endif
7c673cae
FG
102
103
104 // This variable is printed at the end of the test,
105 // to prevent the optimizer from removing the call to
106 // count() in the loop below.
107 typename boost::dynamic_bitset<T>::size_type dummy = 0;
108
109 std::cout << "\nTimings for dynamic_bitset<" << typeid(T).name()
110 << "> [" << num << " iterations]\n";
111 std::cout << "--------------------------------------------------\n";
112
113 {
92f5a8d4 114 boost::timer::auto_cpu_timer time;
7c673cae
FG
115
116 const typename boost::dynamic_bitset<T>::size_type sz = 5000;
117 for (unsigned long i = 0; i < num; ++i) {
118 boost::dynamic_bitset<T> bs(sz, i);
119 dummy += bs.count();
120 }
7c673cae
FG
121 }
122
123 std::cout << "(total count: " << dummy << ")\n\n";
124}
125
126
127
128int main()
129{
130 prologue();
131
132 timing_test<unsigned char>();
133 timing_test<unsigned short>();
134 timing_test<unsigned int>();
135 timing_test<unsigned long>();
136# ifdef BOOST_HAS_LONG_LONG
137 timing_test< ::boost::ulong_long_type>();
138# endif
139
140 return boost::exit_success;
141}
142