| 1 | #include <sys/time.h>
|
|---|
| 2 | #include <boost/container/vector.hpp>
|
|---|
| 3 | #include <vector>
|
|---|
| 4 |
|
|---|
| 5 | void test()
|
|---|
| 6 | {
|
|---|
| 7 | int size = 2000000;
|
|---|
| 8 | {
|
|---|
| 9 | struct timeval start, end;
|
|---|
| 10 | gettimeofday(&start, NULL);
|
|---|
| 11 |
|
|---|
| 12 | std::vector<char, std::allocator<char> > vec(size);
|
|---|
| 13 |
|
|---|
| 14 | gettimeofday(&end, NULL);
|
|---|
| 15 | long long time =(end.tv_sec * (unsigned int)1e6 + end.tv_usec) -
|
|---|
| 16 | (start.tv_sec * (unsigned int)1e6 + start.tv_usec);
|
|---|
| 17 | printf("std::vector %llu us\n", time);
|
|---|
| 18 | }
|
|---|
| 19 | {
|
|---|
| 20 | struct timeval start, end;
|
|---|
| 21 | gettimeofday(&start, NULL);
|
|---|
| 22 |
|
|---|
| 23 | boost::container::vector<char, std::allocator<char> > vec(size);
|
|---|
| 24 |
|
|---|
| 25 | gettimeofday(&end, NULL);
|
|---|
| 26 | long long time =(end.tv_sec * (unsigned int)1e6 + end.tv_usec) -
|
|---|
| 27 | (start.tv_sec * (unsigned int)1e6 + start.tv_usec);
|
|---|
| 28 | printf("boost::vector %llu us\n", time);
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | int main(int argc, char **argv)
|
|---|
| 33 | {
|
|---|
| 34 | while(true) {
|
|---|
| 35 | test();
|
|---|
| 36 | usleep(100000);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|