You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					52 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					52 lines
				
				1.2 KiB
			| 
											5 years ago
										 | #pragma once
 | ||
| 
											6 years ago
										 | 
 | ||
| 
											4 years ago
										 | #include <cstdint>
 | ||
|  | #include <ctime>
 | ||
| 
											6 years ago
										 | 
 | ||
|  | #ifdef __APPLE__
 | ||
|  | #define CLOCK_BOOTTIME CLOCK_MONOTONIC
 | ||
|  | #endif
 | ||
|  | 
 | ||
|  | static inline uint64_t nanos_since_boot() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_BOOTTIME, &t);
 | ||
|  |   return t.tv_sec * 1000000000ULL + t.tv_nsec;
 | ||
|  | }
 | ||
|  | 
 | ||
|  | static inline double millis_since_boot() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_BOOTTIME, &t);
 | ||
|  |   return t.tv_sec * 1000.0 + t.tv_nsec * 1e-6;
 | ||
|  | }
 | ||
|  | 
 | ||
|  | static inline double seconds_since_boot() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_BOOTTIME, &t);
 | ||
| 
											5 years ago
										 |   return (double)t.tv_sec + t.tv_nsec * 1e-9;
 | ||
| 
											6 years ago
										 | }
 | ||
|  | 
 | ||
|  | static inline uint64_t nanos_since_epoch() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_REALTIME, &t);
 | ||
|  |   return t.tv_sec * 1000000000ULL + t.tv_nsec;
 | ||
|  | }
 | ||
|  | 
 | ||
|  | static inline double seconds_since_epoch() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_REALTIME, &t);
 | ||
|  |   return (double)t.tv_sec + t.tv_nsec * 1e-9;
 | ||
|  | }
 | ||
|  | 
 | ||
|  | // you probably should use nanos_since_boot instead
 | ||
|  | static inline uint64_t nanos_monotonic() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_MONOTONIC, &t);
 | ||
|  |   return t.tv_sec * 1000000000ULL + t.tv_nsec;
 | ||
|  | }
 | ||
|  | 
 | ||
|  | static inline uint64_t nanos_monotonic_raw() {
 | ||
|  |   struct timespec t;
 | ||
|  |   clock_gettime(CLOCK_MONOTONIC_RAW, &t);
 | ||
|  |   return t.tv_sec * 1000000000ULL + t.tv_nsec;
 | ||
|  | }
 |