1 /* 2 timefn.h - portable time measurement functions 3 Copyright (C) Yann Collet 2023 4 5 GPL v2 License 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License along 18 with this program; if not, write to the Free Software Foundation, Inc., 19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 21 You can contact the author at : 22 - LZ4 source repository : https://github.com/lz4/lz4 23 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c 24 */ 25 26 #ifndef TIMEFN 27 #define TIMEFN 28 29 #if defined(__cplusplus) 30 extern "C" { 31 #endif 32 33 /*-**************************************** 34 * Types 35 ******************************************/ 36 37 typedef unsigned long long Duration_ns; 38 39 /* TIME_t contains a nanosecond time counter. 40 * The absolute value is not meaningful. 41 * It's only valid to compute Duration_ns between 2 measurements. */ 42 typedef struct { 43 Duration_ns t; 44 } TIME_t; 45 #define TIME_INITIALIZER { 0 } 46 47 /*-**************************************** 48 * Time functions 49 ******************************************/ 50 51 /* @return a TIME_t value to be compared to another one in order to compute a duration. 52 * The absolute value returned is meaningless */ 53 TIME_t TIME_getTime(void); 54 55 /* Timer resolution can be low on some platforms. 56 * To improve accuracy, it's recommended to wait for a new tick 57 * before starting benchmark measurements */ 58 void TIME_waitForNextTick(void); 59 60 /* tells if TIME_getTime() returns correct time measurements 61 * in scenarios involving multi-threaded workload. 62 * note : this is not the case if only C90 clock_t measurements are available */ 63 int TIME_support_MT_measurements(void); 64 65 Duration_ns TIME_span_ns(TIME_t clockStart, TIME_t clockEnd); 66 Duration_ns TIME_clockSpan_ns(TIME_t clockStart); 67 68 #if defined(__cplusplus) 69 } 70 #endif 71 72 #endif /* TIMEFN */ 73