2 ms·
If you'd like to skip the assembly, on macOS, mach_absolute_time is generally the highest resolution timer you are going to get (it reads the relevant hardware
by saagarjha 6y ago
If you'd like to skip the assembly, on macOS, mach_absolute_time is generally the highest resolution timer you are going to get (it reads the relevant hardware registers). Its resolution is easy to get, both on ARM:
$ swift
Welcome to Apple Swift version 5.4 (swiftlang-1205.0.26.4 clang-1205.0.19.54).
Type :help for assistance.
1> import Darwin
2> var timebase = mach_timebase_info_data_t(); mach_timebase_info(&timebase)
$R0: kern_return_t = 0
timebase: mach_timebase_info_data_t = {
numer = 125
denom = 3
}
3> 125.0 / 3.0
$R1: Double = 41.666666666666664
and Intel:
$ swift
Welcome to Apple Swift version 5.4 (swiftlang-1205.0.26.4 clang-1205.0.19.54).
Type :help for assistance.
1> import Darwin
2> var timebase = mach_timebase_info_data_t(); mach_timebase_info(&timebase)
$R0: kern_return_t = 0
timebase: mach_timebase_info_data_t = {
numer = 1
denom = 1
}
3> 1.0 / 1.0
$R1: Double = 1