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