I'm in Algorithms and Data Structures at Syracuse University, and for one of the homeworks I finished most of the code, which is supposed to read a text file and convert it into strings to input into a linked list. However, we are supposed to have a timer that times how long it takes to compile all of the strings from the text file. I am currently using the time.h function, but it is not accurate enough, as I need it to be able to measure to milliseconds. Anyone know a good function or piece of code to use to have this work? I would appreciate it greatly if someone is able to help me on this. If I'm not clear enough, just tell me and I'll send you some more info.
You can use timeGetTime(). It measures in milleseconds. You'll need to include <mmsystem.h> and link winmm.lib. A basic exmample would be like this:
//do your stuff to time here
One option is to use the clock() function.
Or there's also function ftime() which has millisec in <sys\timeb.h>
clock_t start, finish;
start = clock();
finish = clock();
time_elap = (finish-start)/CLK_TCK; //or CLOCKS_PER_SEC
cout << "time elapsed:" << time_elap << " sec" << endl;
I got it to work, thanks a lot guys! This thing was due by midnight, so i got a few hours to spare!