These 4 containers, vector, list, map, unordered_map…are important b.c. they represent some of the most commonly used data structures. Internally they are represented as a dynamic array, double linked list, a searchable tree, and a hash.
#include "c_arclib.cpp"
using namespace std;
int main()
{
/*
Define - Vector, List, Map, Unordered_map
*/
vector<int> vector_int;
list<int> list_int;
map<int,int> map_int;
unordered_map<int, int> unordered_map_int;
/*
Define Loop and Time
*/
int i,j,loop1=5, loop2=4294967;
clock_t time_start,time_end,time_diff;
/*
Run Timing Test
*/
for(j=0;j<loop1;j++)
{
time_start=clock();
for(i=0;i<loop2;++i)
{
unordered_map_int.insert(pair<int,int>(rand(),rand()));
/*
map_int.insert(pair<int,int>(rand(),rand()));
vector_int.push_back(rand());
list_int.push_back(rand());
*/
}
time_end=clock();
time_diff=time_end-time_start;
cout << time_diff << endl;
}
/*
Results
Push / Insert
map (insert) 9500
unorderd_map (insert) 3300
list (push) 2600
vector (push) 900
*/
I think you’re probably looking to just do this?
Also, there are more accurate timers than
clock().