| ResidentBiscuit (2651) | |
|
So per the title, I'm developing a FIFO queue (well more also but I just found the problem), and I've realized that time(NULL) is actually not accurate enough for what I'm doing. I have many entries that were actually entered at different times but so close to each other that time(NULL) doesn't pick up on the difference. I'm working on some page replacement algorithms, what do you recommend I use instead? EDIT: Nevermind, just used a counter as an artificial timer and all is working. | |
|
Last edited on
|
|
| andywestken (1966) | |||
|
You'll need a system specific type: *nix timeval sruct, as used with int gettimeofday(timeval *tp, NULL);timeval allows for micro-sec precision, but the system accuracy is prob. more like 10 milli-sec. Win32/Win64 FILETIME struct, as used by
The FILETIME struct uses 100-nanosecond intervals, but the accuracy of the time is nowhere near that. Prob. similar to the *nix case (approx. 10 milli-sec) Andy | |||
|
Last edited on
|
|||
| ResidentBiscuit (2651) | |
| Thanks for the answer, but I was looking for a system-independent solution, as it needs to run on at least Windows and Linux. | |
|
|
|
| JLBorges (1756) | |||
|
> I was looking for a system-independent solution > just used a counter as an artificial timer and all is working Best if all you want to do is time based sequencing. Otherwise (you want actual timepoints), std::chrono::high_resolution_clock is the standard clock with the smallest period. http://en.cppreference.com/w/cpp/chrono/high_resolution_clock
| |||
|
|
|||
| ResidentBiscuit (2651) | |
| Well as of right now I'm only recording number of page faults, though I did not know about the chrono header. I may use this to record more information. | |
|
|
|
| JLBorges (1756) | |
|
> I may use this to record more information. Prefer std::chrono::steady_clock for this (unless its resolution is not fine enough). | |
|
|
|
| andywestken (1966) | ||
If you have a C++11 compliant compiler. | ||
|
|
||
| ne555 (4385) | |
|
Or simply clock() for c++98 By the way, time() and clock() measure different things. I suppose that you want `user' time | |
|
|
|