mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-24 05:52:09 +00:00
Compare commits
7 Commits
boost-1.30
...
boost-1.31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8de249c06d | ||
|
|
9f424b7d4c | ||
|
|
702e7dd26b | ||
|
|
d878395ca6 | ||
|
|
c4a81fc3e8 | ||
|
|
588891f0a1 | ||
|
|
fd8ccde0b4 |
@@ -1039,14 +1039,11 @@ to_ulong() const
|
||||
const size_type nwords =
|
||||
(sizeof(unsigned long) + sizeof(Block) - 1) / sizeof(Block);
|
||||
|
||||
size_type min_nwords = nwords;
|
||||
if (this->m_num_blocks > nwords) {
|
||||
for (size_type i = nwords; i < this->m_num_blocks; ++i)
|
||||
if (this->m_bits[i])
|
||||
throw overflow;
|
||||
}
|
||||
else
|
||||
min_nwords = this->m_num_blocks;
|
||||
|
||||
unsigned long result = 0;
|
||||
size_type N = std::min(sizeof(unsigned long) * CHAR_BIT, this->size());
|
||||
|
||||
126
timing_tests.cpp
126
timing_tests.cpp
@@ -1,85 +1,120 @@
|
||||
// boost::dynamic_bitset timing test ---------------------------------------//
|
||||
|
||||
// (C) Copyright Gennaro Prota 2002.
|
||||
// Permission to copy, use, modify, sell and distribute this software
|
||||
// is granted provided this copyright notice appears in all copies.
|
||||
// This software is provided "as is" without express or implied warranty,
|
||||
// and with no claim as to its suitability for any purpose.
|
||||
// (C) Copyright Gennaro Prota 2002. Permission to copy, use, modify,
|
||||
// sell and distribute this software is granted provided this copyright
|
||||
// notice appears in all copies. This software is provided "as is" without
|
||||
// express or implied warranty, and with no claim as to its suitability
|
||||
// for any purpose.
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
|
||||
//****************************************************************************//
|
||||
|
||||
// WARNING:
|
||||
// ~~~~~~~
|
||||
// This is a preliminary version, for internal testing only.
|
||||
// For now, it stresses the count() function only and has been executed
|
||||
// on a very few platforms. The previous version, for instance, was never
|
||||
// executed on MSVC (boost::bitset<> didn't even compile with it) and at
|
||||
// the first try it crashed at startup, presumably because of a linker bug.
|
||||
// To cope with it, the definition of
|
||||
// NOTE:
|
||||
// ~~~~~
|
||||
// This is a preliminary, incomplete version.
|
||||
//
|
||||
// template <typename T> void timing_test()
|
||||
// If you are interested in having more benchmarks please make a
|
||||
// request on the boost list, which could encourage me to continue
|
||||
// this work.
|
||||
|
||||
// Also, if you use boost::dynamic_bitset on a platform where
|
||||
// CHAR_BIT >= 9 I suggest experimenting with the size of the count
|
||||
// table in detail/dynamic_bitset.hpp and report any interesting
|
||||
// discovery on the list as well.
|
||||
|
||||
//
|
||||
// has been moved before the definition of main()
|
||||
//
|
||||
// LAST MODIFIED: 2 Aug 2002
|
||||
//****************************************************************************//
|
||||
// LAST MODIFIED: 19 Apr 2003
|
||||
// -----------------------------------------------------------------------//
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#if defined (__STL_CONFIG_H) && !defined (__STL_USE_NEW_IOSTREAMS)
|
||||
// for pre 3.0 versions of libstdc++
|
||||
# define BOOST_OLD_IOSTREAMS
|
||||
#endif
|
||||
// ------------------------------------------------- //
|
||||
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#if !defined(BOOST_OLD_IOSTREAMS)
|
||||
# include <ostream>
|
||||
#endif
|
||||
|
||||
|
||||
#include "boost/cstdlib.hpp"
|
||||
#include "boost/version.hpp"
|
||||
#include "boost/timer.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/cstdlib.hpp"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// the m_ prefixes, below, are mainly to avoid problems with g++:
|
||||
// see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html
|
||||
//
|
||||
class boost_version {
|
||||
const int m_major;
|
||||
const int m_minor;
|
||||
const int m_subminor;
|
||||
|
||||
public:
|
||||
boost_version(unsigned long v = BOOST_VERSION):
|
||||
m_major(v / 100000), m_minor(v / 100 % 1000), m_subminor(v % 100) {}
|
||||
|
||||
friend std::ostream & operator<<(std::ostream &, const boost_version &);
|
||||
};
|
||||
|
||||
|
||||
// give up using basic_ostream, to avoid headaches with old libraries
|
||||
std::ostream& operator<<(std::ostream& os, const boost_version & v) {
|
||||
return os << v.m_major << '.' << v.m_minor << '.' << v.m_subminor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void prologue()
|
||||
{
|
||||
std::cout << '\n';
|
||||
std::cout << "Compiler: " << BOOST_COMPILER << '\n';
|
||||
std::cout << "STLPort used? ";
|
||||
# ifdef _STLPORT_VERSION
|
||||
std::cout << "Yes, v." << std::hex << _STLPORT_VERSION;
|
||||
# else
|
||||
std::cout << "No.";
|
||||
# endif
|
||||
std::cout << std::dec << "\n";
|
||||
std::cout << "Std lib : " << BOOST_STDLIB << '\n';
|
||||
std::cout << "Boost v.: " << boost_version() << '\n';
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
void timing_test()
|
||||
void timing_test(T* = 0) // dummy parameter to workaround VC6
|
||||
{
|
||||
const unsigned long num = 10000;
|
||||
|
||||
std::size_t dummy = 0; // this is printed at the end of the test,
|
||||
// to prevent the optimizer to eliminate
|
||||
// the call to count() in the loop below :-)
|
||||
|
||||
const unsigned long num = 100000;
|
||||
|
||||
|
||||
std::cout << "\n\nTimings for dynamic_bitset<" << typeid(T).name()
|
||||
// This variable is printed at the end of the test,
|
||||
// to prevent the optimizer eliminating the call to
|
||||
// count() in the loop below.
|
||||
typename boost::dynamic_bitset<T>::size_type dummy = 0;
|
||||
|
||||
std::cout << "\nTimings for dynamic_bitset<" << typeid(T).name()
|
||||
<< "> [" << num << " iterations]\n";
|
||||
std::cout << "--------------------------------------------------\n";
|
||||
|
||||
{ // new implementation
|
||||
{
|
||||
boost::timer time;
|
||||
|
||||
for (unsigned long i=0; i<num; ++i) {
|
||||
boost::dynamic_bitset<T> bs(std::size_t(5000), i);
|
||||
|
||||
const typename boost::dynamic_bitset<T>::size_type sz = 5000;
|
||||
for (unsigned long i = 0; i < num; ++i) {
|
||||
boost::dynamic_bitset<T> bs(sz, i);
|
||||
dummy += bs.count();
|
||||
}
|
||||
|
||||
const double elaps = time.elapsed();
|
||||
std::cout << "Elapsed: " << elaps << '\n';
|
||||
}
|
||||
|
||||
std::cout << "(total count: " << dummy << ")\n";
|
||||
std::cout << "(total count: " << dummy << ")\n\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -89,13 +124,14 @@ int main()
|
||||
|
||||
prologue();
|
||||
|
||||
timing_test<unsigned char>();
|
||||
timing_test<unsigned short>();
|
||||
timing_test<unsigned int>();
|
||||
timing_test<unsigned long>();
|
||||
# ifdef BOOST_HAS_LONG_LONG
|
||||
timing_test<unsigned long long>();
|
||||
# endif
|
||||
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user