Created
November 9, 2014 02:04
-
-
Save mguentner/72abc688415f0efeffcc to your computer and use it in GitHub Desktop.
Multiset / List sorted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Compile with g++ --std=c++11 container_performance.cpp | |
* Sample output: | |
* Time for multiset: 13590 ms | |
* Time for List insert: 620 ms | |
* Time for List sort: 8989 ms | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <set> | |
#include <list> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
#define TESTSIZE 10000000 | |
int main(void) { | |
struct timeval start,end; | |
std::vector<int> baseVector; | |
std::list<int> testList; | |
std::multiset<int> testSet; | |
srand(time(NULL)); | |
for (uint64_t i=0; i<TESTSIZE; i++) { | |
baseVector.push_back(rand()); | |
} | |
gettimeofday(&start, NULL); | |
for (auto &e : baseVector) { | |
testSet.insert(e); | |
} | |
gettimeofday(&end, NULL); | |
std::cout << "Time for multiset: " << (end.tv_sec*1000+end.tv_usec/1000)-(start.tv_sec*1000+start.tv_usec/1000) << " ms" << std::endl; | |
gettimeofday(&start, NULL); | |
for (auto &e : baseVector) { | |
testList.push_back(e); | |
} | |
gettimeofday(&end, NULL); | |
std::cout << "Time for List insert: " << (end.tv_sec*1000+end.tv_usec/1000)-(start.tv_sec*1000+start.tv_usec/1000) << " ms" << std::endl; | |
testList.sort(); | |
gettimeofday(&end, NULL); | |
std::cout << "Time for List sort: " << (end.tv_sec*1000+end.tv_usec/1000)-(start.tv_sec*1000+start.tv_usec/1000) << " ms" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment