Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / blenlib / PIL_time_utildefines.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file \ingroup bli
21  *  \brief Utility defines for timing/benchmarks.
22  */
23
24 #ifndef __PIL_TIME_UTILDEFINES_H__
25 #define __PIL_TIME_UTILDEFINES_H__
26
27 #include "PIL_time.h"  /* for PIL_check_seconds_timer */
28 #include "BLI_utildefines.h"  /* for AT */
29
30 #define TIMEIT_START(var)                                                     \
31         {                                                                         \
32                 double _timeit_##var = PIL_check_seconds_timer();                     \
33                 printf("time start (" #var "):  " AT "\n");                           \
34                 fflush(stdout);                                                       \
35                 { (void)0
36
37 /**
38  * \return the time since TIMEIT_START was called.
39  */
40 #define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var)
41
42 #define TIMEIT_VALUE_PRINT(var)                                               \
43         {                                                                         \
44                 printf("time update   (" #var "): %.6f" "  " AT "\n", TIMEIT_VALUE(var));\
45                 fflush(stdout);                                                       \
46         } (void)0
47
48 #define TIMEIT_END(var)                                                       \
49                 }                                                                     \
50                 printf("time end   (" #var "): %.6f" "  " AT "\n", TIMEIT_VALUE(var));\
51                 fflush(stdout);                                                       \
52         } (void)0
53
54 /**
55  * _AVERAGED variants do same thing as their basic counterpart, but additionally add elapsed time to an averaged
56  * static value, useful to get sensible timing of code running fast and often.
57  */
58 #define TIMEIT_START_AVERAGED(var)                                            \
59         {                                                                         \
60                 static float _sum_##var = 0.0f;                                       \
61                 static float _num_##var = 0.0f;                                       \
62                 double _timeit_##var = PIL_check_seconds_timer();                     \
63                 printf("time start    (" #var "):  " AT "\n");                        \
64                 fflush(stdout);                                                       \
65                 { (void)0
66
67 #define TIMEIT_AVERAGED_VALUE(var) (_num##var ? (_sum_##var / _num_##var) : 0.0f)
68
69 #define TIMEIT_END_AVERAGED(var)                                              \
70                 }                                                                     \
71                 const float _delta_##var = TIMEIT_VALUE(var);                         \
72                 _sum_##var += _delta_##var;                                           \
73                 _num_##var++;                                                         \
74                 printf("time end      (" #var "): %.6f" "  " AT "\n", _delta_##var);  \
75                 printf("time averaged (" #var "): %.6f (total: %.6f, in %d runs)\n",  \
76                        (_sum_##var / _num_##var), _sum_##var, (int)_num_##var);       \
77                 fflush(stdout);                                                       \
78         } (void)0
79
80 /**
81  * Given some function/expression:
82  *   TIMEIT_BENCH(some_function(), some_unique_description);
83  */
84 #define TIMEIT_BENCH(expr, id)                                                \
85         {                                                                         \
86                 TIMEIT_START(id);                                                     \
87                 (expr);                                                               \
88                 TIMEIT_END(id);                                                       \
89         } (void)0
90
91 #define TIMEIT_BLOCK_INIT(id)                                                 \
92         double _timeit_var_##id = 0
93
94 #define TIMEIT_BLOCK_START(id)                                                \
95         {                                                                         \
96                 double _timeit_block_start_##id = PIL_check_seconds_timer();          \
97                 { (void)0
98
99 #define TIMEIT_BLOCK_END(id)                                                  \
100                 }                                                                     \
101                 _timeit_var_##id += (PIL_check_seconds_timer() -                      \
102                                      _timeit_block_start_##id);                       \
103         } (void)0
104
105 #define TIMEIT_BLOCK_STATS(id)                                                \
106         {                                                                         \
107                 printf("%s time (in seconds): %f\n", #id, _timeit_var_##id);          \
108                 fflush(stdout);                                                       \
109         } (void)0
110
111 #endif  /* __PIL_TIME_UTILDEFINES_H__ */