In a class, how would I keep track of time using two functions? One to start the timer and another to stop the timer? I tried a few things with clock() and time(), but they gave me the same times in both function, like it resets. Is there anyway to not make the time reset in the functions?
So you have a class say [Duration] with two methods [StartTimer] & [StopTimer].
You then set some member variable of the class with the clock / time result when [StartTimer] is called, and then calculate the duration (probably stored in another member variable) when [StopTimer] is called by subtracting stored [StartTimer] clock/time result from the current result when StopTimer is called.
The function you are trying to calculate the duration of execution may be too quick for the resolution given by clock/time methods. You can test this by adding a significantly long sleep in the function you wish to time. If your Duration object then displays a realistic value, you will then at least be sure that your logic used in class Duration is correct and only need to swap out your use of clock/time with something that has greater resolution. Are you developing this on linux? If so, you can do a man time, or man time(1) (if memory is correct) and see what other functions are provided that offer higher resolution.
Does this help or am I not understanding your question correctly?
I made my program run a little longer and not sure if it works, have a few questions before I can figure it out if it works.
If I have the startTime and stopTime, which I got by using clock(), if I subtract them, I should get the clock in between the program. Now, what format is the clock that I get from subtracting the stop from the start? Is it in seconds or?
clock() returns clock ticks. If you divide the number of ticks by CLOCKS_PER_SEC you get seconds elapsed. If you want it to be more precise that whole seconds you'll have to store the result in a float or double.