I have the following:
vector<int> vec;
template<class T>
bool Add(const T& t)
{
auto i = vec.begin();
while (i != vec.end() && (*i) < t)
++i;
if (i == vec.end())
vec.push_back(t);
else
vec.insert(i, t);
return true;
}
int main()
{
clock_t start, finish;
const int MAX = 100;
start = clock();
for (int i = 0; i < MAX; i++)
{
int t = rand() % RAND_MAX;
Add(t);
}
finish = clock();
cout << "Time: " << finish - start << " clicks" << endl;
cout << "Time: " << (double)(finish - start) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
I'm trying to measure the amount of time it takes to generate a random number and add it into a vector but my output is:
Time: 0 clicks
Time: 0 seconds
Am I not measuring the lapsed time properly?