| 1 | //============================================================================
|
|---|
| 2 | // Name : test.cpp
|
|---|
| 3 | // Author : Gerhard Holzmeister
|
|---|
| 4 | // Description : Test complexity of ~stable_vector()
|
|---|
| 5 | //============================================================================
|
|---|
| 6 |
|
|---|
| 7 | #include <boost/container/stable_vector.hpp>
|
|---|
| 8 | #include <boost/chrono/system_clocks.hpp>
|
|---|
| 9 | #include <iostream>
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | void test(int size)
|
|---|
| 14 | {
|
|---|
| 15 |
|
|---|
| 16 | typedef boost::chrono::steady_clock clock;
|
|---|
| 17 |
|
|---|
| 18 | clock::time_point t0 = clock::now() ;
|
|---|
| 19 |
|
|---|
| 20 | boost::container::stable_vector<int> * ptrVector = new boost::container::stable_vector<int>();
|
|---|
| 21 |
|
|---|
| 22 | for (int i = 0; i < size; i++)
|
|---|
| 23 | {
|
|---|
| 24 | ptrVector->push_back(i);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | clock::time_point t1 = clock::now() ;
|
|---|
| 28 |
|
|---|
| 29 | delete ptrVector;
|
|---|
| 30 |
|
|---|
| 31 | clock::time_point t2 = clock::now() ;
|
|---|
| 32 |
|
|---|
| 33 | clock::duration dt1 = t1 - t0;
|
|---|
| 34 | clock::duration dt2 = t2 - t1;
|
|---|
| 35 |
|
|---|
| 36 | std::cout << "size: " << size << " create and fill time/size:" << dt1.count()/size << " delete time/size:" << dt2.count()/size << std::endl;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | int main()
|
|---|
| 40 | {
|
|---|
| 41 | for (int i = 1000; i < 65000; i+=i)
|
|---|
| 42 | {
|
|---|
| 43 | test(i);
|
|---|
| 44 | }
|
|---|
| 45 | return 0;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|