also benchmark bost:container::deque

This commit is contained in:
Andreas Fabri 2014-12-12 09:45:17 +01:00
parent 1bc624ee30
commit 6adece5ee9
2 changed files with 33 additions and 9 deletions

View File

@ -4,35 +4,49 @@
#include <CGAL/array.h> #include <CGAL/array.h>
#include <CGAL/Block_list.h> #include <CGAL/Block_list.h>
#include <CGAL/Timer.h> #include <CGAL/Timer.h>
#include <boost/container/deque.hpp>
#if 1 //
// leaf
struct X { struct X {
double a,b,c,d,e,f,g,h,i,j,k,l; bool b;
int i;
double d1;
}; };
#else
// internal
struct X {
bool b;
int i;
double d1, d2, d3, d4,d5;
};
#endif
int main() int main()
{ {
CGAL::Memory_sizer ms; CGAL::Memory_sizer ms;
CGAL::Timer t; CGAL::Timer t;
char c;
t.start(); t.start();
#if 0 #if 0
std::cout <<"blocklist"<< std::endl;
CGAL::Block_list<X, 256> de; CGAL::Block_list<X, 256> de;
#elif 1 #elif 0
std::cout <<"boost::container::deque"<< std::endl;
boost::container::deque<X> de;
#elif 0
std::cout <<"std::deque"<< std::endl;
std::deque<X> de; std::deque<X> de;
#else #else
std::cout <<"vector"<< std::endl;
std::vector<X> de; std::vector<X> de;
de.reserve(100000000); // de.reserve(100000000);
#endif #endif
for(int i=0; i < 100000000; i++){ for(int i=0; i < 10000000; i++){
de.push_back(X()); de.push_back(X());
} }
t.stop(); t.stop();
std::cout << t.time() << "sec"<< std::endl; std::cout << t.time() << "sec"<< std::endl;
std::cout << ms.virtual_size() << " " << ms.resident_size() << std::endl; std::cout << ms.virtual_size() << " " << ms.resident_size() << std::endl;
std::cout << "cont>" << std::endl;
std::cin >> c;
return 0; return 0;
} }

View File

@ -12,12 +12,20 @@ namespace CGAL {
typedef CGAL::cpp11::array<T,N> Block; typedef CGAL::cpp11::array<T,N> Block;
int index; int index;
std::list<Block> blocks; std::list<Block> blocks;
typedef typename std::list<Block>::iterator List_iterator;
typedef typename Block::iterator Block_iterator;
public: public:
Block_list() Block_list()
: index(N) : index(N)
{} {}
std::size_t size() const
{
return (index == N)? (blocks.size()*N) : ((blocks.size()-1)*N+index);
}
T* push_back(const T& t) T* push_back(const T& t)
{ {
if(index==N){ if(index==N){
@ -32,6 +40,8 @@ namespace CGAL {
return ptr; return ptr;
} }
void clear() void clear()
{ {
blocks.clear(); blocks.clear();