I'm not all too familiar with it either, it's just what I found with a google search. But it returns total seconds and microseconds. So multiplying seconds by 1000 converts seconds to milliseconds and dividing by 1000 converts microseconds into milliseconds. It made sense to me, but I might be missing something obvious again. Why should I not divide?
Anyway, I changed things a bit to time only the sorts. Here's what I have
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include "header.h"
void RunTest(vector<float>& inputs, int test_number, ofstream& output_file)
{
string name;
GenerateInputFiles("input", 100, test_number);
//the time variables, used for keeping track of the elapsed time for each sort
timeval initial;
timeval final;
long initial_ms;
long final_ms;
long difference;
//a vector of input vectors used to store the inputs from each text file
vector<vector<float> > vector_of_inputs;
//get the inputs from each text file
for(int i = 0; i < 100; i++)
{
inputs.clear();
name = "input" + GetStringFromInt(i) + ".txt";
GetInputs(inputs, name);
vector_of_inputs.push_back(inputs);
}
//start keeping track of the time
gettimeofday(&initial, NULL);
initial_ms = (initial.tv_sec * 1000.0) + (initial.tv_usec / 1000.0);
for(int i = 0; i < 100; i++)
{
inputs.clear();
inputs = vector_of_inputs[i];
Sort(inputs, 0, inputs.size() - 1);
//PrintVector(inputs);
}
//end timer
gettimeofday(&final, NULL);
final_ms = (final.tv_sec * 1000.0) + (final.tv_usec / 1000.0);
difference = final_ms - initial_ms;
output_file << "\nElapsed Time: " << difference << "\n";
}
|
And as far as I can tell it's working, but the values are still really small (not necessarily wrong, but it's worth asking about). I haven't divided yet to get the average, so it's the total elapsed time. What I have right now is this:
for 10 inputs: 0 milliseconds
for 100 inputs: 2 milliseconds
for 1000 inputs: 27 milliseconds
for 10000 inputs: 414 milliseconds
Is there anything that I'm obviously doing wrong?