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.
		
		
		
		
			
				
					32 lines
				
				716 B
			
		
		
			
		
	
	
					32 lines
				
				716 B
			| 
								 
											9 years ago
										 
									 | 
							
								#ifndef COMMON_TIMING_H
							 | 
						||
| 
								 | 
							
								#define COMMON_TIMING_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include <stdint.h>
							 | 
						||
| 
								 | 
							
								#include <time.h>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								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 / 1000000.0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								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 / 1000000000.0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif
							 |