What is the Difference Between the `SECONDS()` and `UPTIME()` Functions?

The UPTIME function returns NSProcessInfo.processInfo.systemUptime, the time that the Mac has been up since.

You should use that if what you want to know is how long since the Mac has been booted.

SECONDS function returns CACurrentMediaTime() (give or take a microsecond) which in turn is based on mach_absolute_time() which the according to the documentation says Returns current value of a clock that increments monotonically in tick units (starting at an arbitrary point), this clock does not increment while the system is asleep.

You should use that if you want to keep track of time differences for short periods (such as timing how long a macro takes to execute).

The purpose of the CACurrentMediaTime is related to media syncing/timing I believe.

That said, in any experiment I carry out, whether the Mac has slept or not, the two stay in sync. So take it up with Apple.

But basically, don't rely on the two being the same, use them for their respective purposes.

Don't rely on the precision of the UPTIME() function. Assume it might update only every second or two.

Similarly, don't rely on the long term value of the SECONDS() function. Assume it might lose time if the Mac slept.

4 Likes