Well, my first suggestion would be to use core.time or std.datetime. It has a StopWatch . Isn't that fast enough? He uses any standard monotonous clock for the system, and I hope that it will be fast enough. This is by far the highest accuracy you are going to get (although I donβt know how high accuracy affects speed). However, if it's not fast enough, I'm not sure if your other options are better. As a rule, you get either the second accuracy or high accuracy. There is not much between them. And with high accuracy, as a rule, at least microsecond accuracy, and the question is how much superior it is. 1/4 second accuracy is not entirely normal.
The Cybershadow clock proposal can do the trick - of course, this is your only option, which is standard C as far as I know - but it may or may not be fast enough.
Besides clock ... On Linux, if you want a non-monotonous way to get time with higher accuracy than one second, I find gettimeofday to be your only real option, but I don't know how fast it is. On Windows, the best non-monotonous solution I know of is getSystemTimeAsFiletime , but Windows has a few time functions that you could play with.
You can look at std.datetime Clock.currStdTime to find out how to make any of them (although it uses clock_gettime in Posix, if available, and this is what core.time uses - albeit with different clocks - so you probably , you want the else part of this function for Linux, if StopWatch too slow for you). However, it will convert to hnsecs from midnight January 1, 1 AD, so depending on what you do with the number, you might want to skip this part of the calculation.
Jonathan m davis
source share