- #Bash on mac get time in milliseconds how to#
- #Bash on mac get time in milliseconds portable#
- #Bash on mac get time in milliseconds software#
Query a timer frequency (ticks per second) with QueryPerformanceFrequency: LARGE_INTEGER tcounter To acquire a high precision time stamp on Windows you should:
#Bash on mac get time in milliseconds software#
There is a great article called Acquiring high-resolution time stamps on MSDN about time measurement on Windows which describes all the details you may need to know about software and hardware support.
#Bash on mac get time in milliseconds portable#
When implementing a portable solution it is worth to consider a fallback strategy: use a monotonic clock if available and fallback to time stamps approach if there is no monotonic clock in the system. It usually has a high precision, and it is reliable by design. So the first rule in time interval measuring is to use a monotonic clock if possible. Actually this kind of time source is less reliable than the first one. In some circumstances you can get a negative elapsed time value which can lead to an undefined behavior. time zone change, daylight saving time (DST) change, NTP server update, system hibernation and so on. It may also have a high resolution, but it has one major drawback: this kind of time value can be affected by different system time adjustments, i.e. The second way provides a (date)time value based on the current system clock value. Usually the frequency is bound to a hardware high-resolution source, that's why it provides a high accuracy (depends on hardware, but most of the modern hardware has no problems with high-resolution clock sources). But it guarantees that a clock is always run up in an increasing fashion regardless of the system state. It is actually not guaranteed that a monotonic clock reflects the current system time in any way, it may also count ticks since a system startup. The first one uses a monotonic clock counter (sometimes it is called a tick counter) which counts ticks with a predefined frequency, so if you have a ticks value and the frequency is known, you can easily convert ticks to elapsed time. Generally speaking there are two ways of time measurement:
#Bash on mac get time in milliseconds how to#
As it was already mentioned here that there is no proper ANSI solution with sufficient precision for the time measurement problem, I want to write about the ways how to get a portable and, if possible, a high-resolution time measurement solution.