SMIL  1.0.4
DBench.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _DBENCH_H
31 #define _DBENCH_H
32 
33 #include "DTime.h"
34 #include "DCommon.h"
35 #include "DBaseImage.h"
36 
37 namespace smil
38 {
39  #define BENCH(func, ...) \
40  { \
41  double t1, t2; \
42  t1 = getCpuTime(); \
43  for (UINT i=0;i<BENCH_NRUNS;i++) \
44  func(__VA_ARGS__); \
45  t2 = getCpuTime(); \
46  cout << #func << "\t" << displayTime((t2-t1)/BENCH_NRUNS) << endl; \
47  }
48 
49  #define BENCH_STR(func, str, ...) \
50  { \
51  double t1, t2; \
52  t1 = getCpuTime(); \
53  for (UINT i=0;i<BENCH_NRUNS;i++) \
54  func(__VA_ARGS__); \
55  t2 = getCpuTime(); \
56  cout << #func << " " << str << "\t" << displayTime((t2-t1)/BENCH_NRUNS) << endl; \
57  }
58 
59  #define BENCH_IMG(func, ...) \
60  { \
61  double t1, t2; \
62  t1 = getCpuTime(); \
63  for (UINT i=0;i<BENCH_NRUNS;i++) \
64  func(__VA_ARGS__); \
65  t2 = getCpuTime(); \
66  cout << #func << "\t" << GET_1ST_ARG(__VA_ARGS__).getTypeAsString() << "\t"; \
67  cout << GET_1ST_ARG(__VA_ARGS__).getWidth() << "x" << GET_1ST_ARG(__VA_ARGS__).getHeight(); \
68  if (GET_1ST_ARG(__VA_ARGS__).getDepth()>UINT(1)) cout << "x" << GET_1ST_ARG(__VA_ARGS__).getDepth(); \
69  cout << "\t" << displayTime((t2-t1)/BENCH_NRUNS) << endl; \
70  }
71 
72  #define BENCH_CROSS_IMG(func, ...) \
73  { \
74  double t1, t2; \
75  t1 = getCpuTime(); \
76  for (UINT i=0;i<BENCH_NRUNS;i++) \
77  func(__VA_ARGS__); \
78  t2 = getCpuTime(); \
79  cout << #func << "\t" << GET_1ST_ARG(__VA_ARGS__).getTypeAsString() << "-" << GET_2ND_ARG(__VA_ARGS__).getTypeAsString() << "\t"; \
80  cout << GET_1ST_ARG(__VA_ARGS__).getWidth() << "x" << GET_1ST_ARG(__VA_ARGS__).getHeight(); \
81  if (GET_1ST_ARG(__VA_ARGS__).getDepth()>UINT(1)) cout << "x" << GET_1ST_ARG(__VA_ARGS__).getDepth(); \
82  cout << "\t" << displayTime((t2-t1)/BENCH_NRUNS) << endl; \
83  }
84 
85  #define BENCH_IMG_STR(func, str, ...) \
86  { \
87  double t1, t2; \
88  t1 = getCpuTime(); \
89  for (UINT i=0;i<BENCH_NRUNS;i++) \
90  func(__VA_ARGS__); \
91  t2 = getCpuTime(); \
92  cout << #func << " " << str << "\t" << GET_1ST_ARG(__VA_ARGS__).getTypeAsString() << "\t"; \
93  cout << GET_1ST_ARG(__VA_ARGS__).getWidth() << "x" << GET_1ST_ARG(__VA_ARGS__).getHeight(); \
94  if (GET_1ST_ARG(__VA_ARGS__).getDepth()>1) cout << "x" << GET_1ST_ARG(__VA_ARGS__).getDepth(); \
95  cout << "\t" << displayTime((t2-t1)/BENCH_NRUNS) << endl; \
96  }
97 
98 } // namespace smil
99 
100 
101 #endif // _DBENCH_H
102