Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/dynamic_bitset/example/timing_tests.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

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