I keep getting zero as my time. I need to calculate the total time and the average time for searching though the hash table. Can someone please tell me what i am doing wrong?
void HashTable_chaining::SearchChainingHT(vector<string> QueryArray)
{
clock_t start, stop, time = 0;
int i = 0;
while(i != QueryArray.size())
{
start = clock();
find(QueryArray[i]);
stop = clock();
time += stop - start;
i++;
}
time = (double)(time/CLOCKS_PER_SEC)*1000;
cout << "\nThe total time for Search Chaining was " << time << "\nThe average time was " << time/QueryArray.size();
}
You’re doing integer division:
you want the cast inside the
()instead:Furthermore, I’m not sure why you are assigning it back to
timesince that’s an integer variable. If you wanted it in milliseconds, you might want to make it explicit:EDIT :
I overlooked this initially (because of the horizontal scrolling), but you also have integer division here at the end of the printing line:
You may want to cast that one to
doubleas well.