/usr/include/BALL/CONCEPT/benchmark.h is in libball1.4-dev 1.4.1+20111206-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_SYSTEM_TIMER_H
# include <BALL/SYSTEM/timer.h>
#endif
#include <string>
/** Start a new benchmark section.
The argument weight determines the weighting factor of the section.
\ingroup Benchmark
*/
#define START_SECTION(name, weight) \
BENCHMARK::section_time = BENCHMARK::timer.getCPUTime();\
BENCHMARK::section_name = #name;\
BENCHMARK::section_weight = weight;
/** End of a benchmark section.
\ingroup Benchmark
*/
#define END_SECTION \
BENCHMARK::timer.stop();\
BENCHMARK::section_time = BENCHMARK::timer.getCPUTime() - BENCHMARK::section_time;\
if (BENCHMARK::verbose > 0)\
{\
std::cout << BENCHMARK::section_name << ": " \
<< BENCHMARK::section_time << " s"\
<< " (weight = " << BENCHMARK::section_weight << ")" << std::endl;\
}\
BENCHMARK::total_time += BENCHMARK::section_time * BENCHMARK::section_weight;\
/** Status output.
Print debugging information if called with -v.
\ingroup Benchmark
*/
#define STATUS(a) \
if (BENCHMARK::verbose > 0)\
{\
std::cout << " status: " << a << std::endl;\
}
/** Start the timer.
This macro is used to determine the running time of a set of commands.
It may be used in benchmarks and requires a prior invocation of the
\link #START_BENCHMARK START_BENCHMARK \endlink macro.
All commands that are between the START_TIMER and the \link #STOP_TIMER STOP_TIMER \endlink
command contribute to the overall running time of the benchmark.
\ingroup Benchmark
*/
#define START_TIMER \
BENCHMARK::timer.start();\
/** Stop the timer.
This macro is used to determine the running time of a set of commands.
It may be used in benchmarks and requires a prior invocation of the
\link #START_BENCHMARK START_BENCHMARK \endlink and \link #START_TIMER START_TIMER \endlink macros.
All commands that are between the START_TIMER and the \link #STOP_TIMER STOP_TIMER \endlink
command contribute to the overall running time of the benchmark.
\ingroup Benchmark
*/
#define STOP_TIMER \
BENCHMARK::timer.stop();
/** Program body for the benchmark.
The parameter <tt>weight</tt> determines the overall weight of
this test in the accumulated benchmark (BALLStones).
\ingroup Benchmark
*/
#define START_BENCHMARK(class_name, overall_weight, version)\
/* define a special namespace for all internal variables */\
/* to avoid potential collisions */\
namespace BENCHMARK {\
int verbose = 0;\
bool all_tests = true;\
int exception = 0;\
string exception_name = "";\
const char* version_string = version;\
string section_name = "";\
float section_weight = 1.0;\
float weight = overall_weight;\
float total_time;\
float section_time;\
BALL::Timer timer;\
}\
\
\
int main(int argc, char **argv)\
{\
\
if (argc == 2) {\
if (!strcmp(argv[1], "-v"))\
BENCHMARK::verbose = 1;\
};\
\
if ((argc > 2) || ((argc == 2) && (BENCHMARK::verbose == 0))) {\
std::cerr << "Execute a benchmark for the " #class_name " class." << std::endl;\
std::cerr << "Overall weight of the test: " << BENCHMARK::weight << std::endl;\
\
std::cerr << "On successful operation, the total CPU time (in seconds)," << std::endl;\
std::cerr << "is printed." << std::endl;\
std::cerr << "If called with an argument of -v, " << argv[0] << " detailed" << std::endl;\
std::cerr << "information about individual benchmarks is printed." << std::endl;\
return 1;\
}\
\
if (BENCHMARK::verbose > 0)\
std::cout << "Version: " << BENCHMARK::version_string << std::endl;\
\
try {\
/** End of the test program
\ingroup Benchmark
*/
#define END_BENCHMARK \
/* global try block */\
}\
/* catch FileNotFound exceptions to print out the file name */\
catch (BALL::Exception::FileNotFound& e)\
{\
BENCHMARK::all_tests = false;\
if (BENCHMARK::verbose > 1)\
{\
if (BENCHMARK::exception == 1) /* dummy to avoid compiler warnings */\
BENCHMARK::exception++;\
std::cout << std::endl << " (caught exception of type ";\
std::cout << e.getName();\
if ((e.getLine() > 0) && (!(e.getFile() == "")))\
std::cout << " outside a benchmark block, which was thrown in line " << e.getLine() << " of file " << e.getFile();\
std::cout << " while looking for file " << e.getFilename();\
std::cout << " - unexpected!) " << std::endl;\
}\
}\
/* catch BALL exceptions to retrieve additional information */\
catch (BALL::Exception::GeneralException& e)\
{\
BENCHMARK::all_tests = false;\
if (BENCHMARK::verbose > 1)\
{\
if (BENCHMARK::exception == 1) /* dummy to avoid compiler warnings */\
BENCHMARK::exception++;\
std::cout << std::endl << " (caught exception of type ";\
std::cout << e.getName();\
if ((e.getLine() > 0) && (!(e.getFile() == "")))\
std::cout << " outside a benchmark block, which was thrown in line " << e.getLine() << " of file " << e.getFile();\
std::cout << " - unexpected!) " << std::endl;\
}\
}\
/* catch all non-BALL exceptions */\
catch (...)\
{\
BENCHMARK::all_tests = false;\
if (BENCHMARK::verbose > 1)\
{\
std::cout << std::endl << " (caught unidentified and unexpected exception outside a benchmark block!) " << std::endl;\
}\
}\
\
/* check for exit code */\
if (!BENCHMARK::all_tests)\
{\
std::cout << "(" << BENCHMARK::weight * BENCHMARK::total_time << ")" << std::endl;\
return 1;\
} else {\
std::cout << BENCHMARK::weight * BENCHMARK::total_time << std::endl;\
return 0;\
}\
}\
|