Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under both the BSD-style license (found in the |
| 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found |
| 7 | * in the COPYING file in the root directory of this source tree). |
| 8 | * You may select, at your option, one of the above-listed licenses. |
| 9 | */ |
| 10 | |
| 11 | #ifndef TIME_FN_H_MODULE_287987 |
| 12 | #define TIME_FN_H_MODULE_287987 |
| 13 | |
| 14 | #if defined (__cplusplus) |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 19 | |
| 20 | /*-**************************************** |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 21 | * Types |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 22 | ******************************************/ |
| 23 | |
| 24 | #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) |
Like Ma | cc90777 | 2020-08-26 03:10:06 +0800 | [diff] [blame] | 25 | # if defined(_AIX) |
| 26 | # include <inttypes.h> |
| 27 | # else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 28 | # include <stdint.h> /* uint64_t */ |
Like Ma | cc90777 | 2020-08-26 03:10:06 +0800 | [diff] [blame] | 29 | # endif |
Yann Collet | 4b8185c | 2019-04-10 13:26:27 -0700 | [diff] [blame] | 30 | typedef uint64_t PTime; /* Precise Time */ |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 31 | #else |
Yann Collet | 4b8185c | 2019-04-10 13:26:27 -0700 | [diff] [blame] | 32 | typedef unsigned long long PTime; /* does not support compilers without long long support */ |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 33 | #endif |
| 34 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 35 | /* UTIL_time_t contains a nanosecond time counter. |
| 36 | * The absolute value is not meaningful. |
| 37 | * It's only valid to compute the difference between 2 measurements. */ |
| 38 | typedef struct { PTime t; } UTIL_time_t; |
| 39 | #define UTIL_TIME_INITIALIZER { 0 } |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 40 | |
Yann Collet | 4b8185c | 2019-04-10 13:26:27 -0700 | [diff] [blame] | 41 | |
Yann Collet | 8b13000 | 2023-01-06 15:25:36 -0800 | [diff] [blame] | 42 | /*-**************************************** |
| 43 | * Time functions |
| 44 | ******************************************/ |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 45 | |
Yann Collet | 8b13000 | 2023-01-06 15:25:36 -0800 | [diff] [blame] | 46 | UTIL_time_t UTIL_getTime(void); |
Evan Witt | 7993493 | 2023-09-06 22:46:11 +0000 | [diff] [blame] | 47 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 48 | /* Timer resolution can be low on some platforms. |
| 49 | * To improve accuracy, it's recommended to wait for a new tick |
| 50 | * before starting benchmark measurements */ |
| 51 | void UTIL_waitForNextTick(void); |
| 52 | /* tells if timefn will return correct time measurements |
| 53 | * in presence of multi-threaded workload. |
| 54 | * note : this is not the case if only C90 clock_t measurements are available */ |
| 55 | int UTIL_support_MT_measurements(void); |
| 56 | |
| 57 | PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd); |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 58 | PTime UTIL_clockSpanNano(UTIL_time_t clockStart); |
| 59 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 60 | PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd); |
| 61 | PTime UTIL_clockSpanMicro(UTIL_time_t clockStart); |
| 62 | |
| 63 | #define SEC_TO_MICRO ((PTime)1000000) /* nb of microseconds in a second */ |
Yann Collet | 59a7116 | 2019-04-10 12:37:03 -0700 | [diff] [blame] | 64 | |
| 65 | |
| 66 | #if defined (__cplusplus) |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | #endif /* TIME_FN_H_MODULE_287987 */ |