Made PIL_time_utildefines self-sufficient
[blender.git] / source / blender / blenlib / PIL_time_utildefines.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): Campbell Barton
24  *                 Sergey Sharybin
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/blenlib/PIL_time_utildefines.h
30  *  \ingroup bli
31  *  \brief Utility defines for timing/benchmarks.
32  */
33
34 #ifndef __PIL_TIME_UTILDEFINES_H__
35 #define __PIL_TIME_UTILDEFINES_H__
36
37 #include "PIL_time.h"  /* for PIL_check_seconds_timer */
38 #include "BLI_utildefines.h"  /* for AT */
39
40 #define TIMEIT_START(var)                                                     \
41         {                                                                         \
42                 double _timeit_##var = PIL_check_seconds_timer();                     \
43                 printf("time start (" #var "):  " AT "\n");                           \
44                 fflush(stdout);                                                       \
45                 { (void)0
46
47 /**
48  * \return the time since TIMEIT_START was called.
49  */
50 #define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var)
51
52 #define TIMEIT_VALUE_PRINT(var)                                               \
53         {                                                                         \
54                 printf("time update(" #var "): %.6f" "  " AT "\n", TIMEIT_VALUE(var));\
55                 fflush(stdout);                                                       \
56         } (void)0
57
58 #define TIMEIT_END(var)                                                       \
59         }                                                                         \
60         printf("time end   (" #var "): %.6f" "  " AT "\n", TIMEIT_VALUE(var));    \
61         fflush(stdout);                                                           \
62 } (void)0
63
64 /**
65  * Given some function/expression:
66  *   TIMEIT_BENCH(some_function(), some_unique_description);
67  */
68 #define TIMEIT_BENCH(expr, id)                                                \
69         {                                                                         \
70                 TIMEIT_START(id);                                                     \
71                 (expr);                                                               \
72                 TIMEIT_END(id);                                                       \
73         } (void)0
74
75 #define TIMEIT_BLOCK_INIT(id) \
76         double _timeit_var_##id = 0; \
77         (void) 0
78
79 #define TIMEIT_BLOCK_START(id)                                                \
80         {                                                                         \
81                 double _timeit_block_start_##id = PIL_check_seconds_timer();          \
82                 { (void)0
83
84 #define TIMEIT_BLOCK_END(id)                                                  \
85                 }                                                                     \
86                 _timeit_var_##id += (PIL_check_seconds_timer() -                      \
87                                      _timeit_block_start_##id);                       \
88         } (void)0
89
90 #define TIMEIT_BLOCK_STATS(id)                                                \
91         {                                                                         \
92                 printf("%s time (in seconds): %f\n", #id, _timeit_var_##id);          \
93                 fflush(stdout);                                                       \
94         } (void)0
95
96 #endif  /* __PIL_TIME_UTILDEFINES_H__ */