9 #ifndef IMPBENCHMARK_MACROS_H
10 #define IMPBENCHMARK_MACROS_H
12 #include <IMP/benchmark/benchmark_config.h>
15 #include <boost/timer.hpp>
16 #include <boost/scoped_ptr.hpp>
17 #include "internal/control.h"
18 #include "internal/flags.h"
20 #include <boost/date_time/posix_time/posix_time.hpp>
21 #include <boost/date_time/posix_time/posix_time_types.hpp>
22 #include <boost/date_time/posix_time/posix_time_duration.hpp>
24 #if IMP_KERNEL_HAS_GPERFTOOLS
25 #include <gperftools/profiler.h>
27 #if IMP_KERNEL_HAS_TCMALLOC_HEAPPROFILER
28 #include <gperftools/heap-profiler.h>
30 #if IMP_KERNEL_HAS_TCMALLOC_HEAPCHECKER
31 #include <gperftools/heap-checker.h>
34 #define IMP_BENCHMARK_RUN \
35 ++IMP::benchmark::internal::current_benchmark; \
36 if ((IMP::benchmark::internal::run_only < 0 || \
37 (IMP::benchmark::internal::run_only >= 0 && \
38 IMP::benchmark::internal::run_only == \
39 IMP::benchmark::internal::current_benchmark)))
41 #if IMP_KERNEL_HAS_GPERFTOOLS
42 #define IMP_BENCHMARK_CPU_PROFILING_BEGIN \
43 if (IMP::benchmark::internal::cpu_profile_benchmarks) { \
44 ProfilerStart(IMP::benchmark::internal::get_file_name(".pprof").c_str()); \
46 #define IMP_BENCHMARK_CPU_PROFILING_END \
47 if (IMP::benchmark::internal::cpu_profile_benchmarks) { \
51 #define IMP_BENCHMARK_CPU_PROFILING_BEGIN
52 #define IMP_BENCHMARK_CPU_PROFILING_END
55 #if IMP_KERNEL_HAS_TCMALLOC_HEAPPROFILER
56 #define IMP_BENCHMARK_HEAP_PROFILING_BEGIN \
57 if (IMP::benchmark::internal::heap_profile_benchmarks) { \
59 IMP::benchmark::internal::get_file_name(".hprof").c_str()); \
61 #define IMP_BENCHMARK_HEAP_PROFILING_END \
62 if (IMP::benchmark::internal::heap_profile_benchmarks) { \
66 #define IMP_BENCHMARK_HEAP_PROFILING_BEGIN
67 #define IMP_BENCHMARK_HEAP_PROFILING_END
70 #if IMP_KERNEL_HAS_TCMALLOC_HEAPCHECKER
71 #define IMP_BENCHMARK_HEAP_CHECKING_BEGIN \
72 boost::scoped_ptr<HeapLeakChecker> heap_checker; \
73 if (IMP::benchmark::internal::heap_check_benchmarks) { \
74 heap_checker.reset(new HeapLeakChecker( \
75 IMP::benchmark::internal::get_file_name("").c_str())); \
77 #define IMP_BENCHMARK_HEAP_CHECKING_END \
78 if (IMP::benchmark::internal::heap_check_benchmarks) { \
79 if (!heap_checker->NoLeaks()) std::cerr << "Leaks found\n"; \
80 heap_checker.reset(IMP_NULLPTR); \
83 #define IMP_BENCHMARK_HEAP_CHECKING_BEGIN
84 #define IMP_BENCHMARK_HEAP_CHECKING_END
87 #define IMP_BENCHMARK_PROFILING_BEGIN \
88 IMP_BENCHMARK_CPU_PROFILING_BEGIN IMP_BENCHMARK_HEAP_CHECKING_BEGIN \
89 IMP_BENCHMARK_HEAP_PROFILING_BEGIN
91 #define IMP_BENCHMARK_PROFILING_END \
92 IMP_BENCHMARK_CPU_PROFILING_END IMP_BENCHMARK_HEAP_CHECKING_END \
93 IMP_BENCHMARK_HEAP_PROFILING_END
97 #define IMP_TIME(block, timev) \
99 boost::timer imp_timer; \
100 unsigned int imp_reps = 0; \
101 IMP_BENCHMARK_PROFILING_BEGIN; \
106 } while (imp_timer.elapsed() < 2.5 && !IMP::run_quick_test); \
108 catch (const IMP::Exception& e) { \
109 std::cerr << "Caught exception " << e.what() << std::endl; \
111 IMP_BENCHMARK_PROFILING_END; \
112 timev = imp_timer.elapsed() / imp_reps; \
120 #define IMP_WALLTIME(block, timev) \
121 IMP_BENCHMARK_RUN { \
122 using namespace boost::posix_time; \
123 ptime start = microsec_clock::local_time(); \
124 unsigned int imp_reps = 0; \
125 IMP_BENCHMARK_PROFILING_BEGIN; \
130 } while (microsec_clock::local_time() - start < seconds(2) && \
131 !IMP::run_quick_test); \
133 catch (const IMP::Exception& e) { \
134 std::cerr << "Caught exception " << e.what() << std::endl; \
136 IMP_BENCHMARK_PROFILING_END; \
137 timev = (microsec_clock::local_time() - start).total_milliseconds() / \
147 #define IMP_TIME_N(block, timev, N) \
148 IMP_BENCHMARK_RUN { \
149 boost::timer imp_timer; \
150 IMP_BENCHMARK_PROFILING_BEGIN; \
151 for (unsigned int i = 0; i < (N); ++i) { \
155 catch (const IMP::Exception& e) { \
156 std::cerr << "Caught exception " << e.what() << std::endl; \
159 if (IMP::run_quick_test) break; \
161 IMP_BENCHMARK_PROFILING_END; \
162 timev = imp_timer.elapsed() / (N); \
Exception definitions and assertions.
Support for shared command line flags.
Provide a nullptr keyword analog.