wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.16k stars 1.05k forks source link

Use macOS clock_gettime in timespec_now if it's available. Reduces CPU usage. #267

Open ajackson-adi opened 2 years ago

ajackson-adi commented 2 years ago

We were finding high CPU usage on macOS when connected to very active serial connections. After running the XCode profiler it pointed to this function.

clock_gettime is available in macOS 10.12 and higher. This change is to use that if it's available. If they are targeting a lower macOS minimum version check it at runtime, otherwise do it at compile time.

CPU usage was reduced to a more acceptable level.