00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_TOOLS_BENCHER_HH
00018 # define VCSN_TOOLS_BENCHER_HH
00019
00020 # ifdef VCSN_BENCH
00021
00022 # include <sys/time.h>
00023 # include <sys/resource.h>
00024 # include <cstdio>
00025 # include <cstring>
00026 # include <cstdlib>
00027 # include <ctime>
00028 # include <iostream>
00029 # include <vector>
00030 # include <string>
00031 # include <utility>
00032
00033 namespace vcsn
00034 {
00035 namespace tools
00036 {
00037 class bencher {
00038 public:
00039 bencher();
00040 ~bencher();
00041
00042 public:
00043 void start();
00044 void stop();
00045 double get_time();
00046
00047 private:
00048 double dtime();
00049
00050 double start_;
00051 double stop_;
00052 };
00053
00054 unsigned int n_bench_indent;
00055 std::vector<bencher*> v_benchers;
00056 std::vector< std::pair<int, bencher*> > v_old_benchers;
00057
00058 # define VCSN_BENCH_START_QUIET \
00059 { \
00060 v_benchers.push_back(new bencher); \
00061 v_benchers.back()->start(); \
00062 }
00063
00064 # define VCSN_BENCH_START \
00065 { \
00066 v_benchers.push_back(new bencher); \
00067 v_benchers.back()->start(); \
00068 std::cerr << std::string(n_bench_indent, ' ') << \
00069 "Start bench in " << __FUNCTION__ << "..." << std::endl; \
00070 n_bench_indent += 3; \
00071 }
00072
00073 # define VCSN_BENCH_STOP_QUIET(Result) \
00074 { \
00075 v_benchers.back()->stop(); \
00076 Result = v_benchers.back()->get_time(); \
00077 delete v_benchers.back(); \
00078 v_benchers.pop_back(); \
00079 }
00080
00081 # define VCSN_BENCH_STOP \
00082 { \
00083 v_benchers.back()->stop(); \
00084 v_old_benchers.insert(v_old_benchers.begin(), \
00085 std::pair<int, bencher*>(n_bench_indent, \
00086 v_benchers.back())); \
00087 n_bench_indent -= 3; \
00088 std::cerr << std::string(n_bench_indent, ' ') << \
00089 "Stop bench in " << __FUNCTION__ << "..." << std::endl; \
00090 v_benchers.pop_back(); \
00091 }
00092
00093 # define VCSN_BENCH_PRINT \
00094 { \
00095 std::cerr << std::string(v_old_benchers.back().first, ' ') << \
00096 __FUNCTION__ << ": " << \
00097 v_old_benchers.back().second->get_time() << std::endl; \
00098 delete v_old_benchers.back().second; \
00099 v_old_benchers.pop_back(); \
00100 }
00101
00102 # define VCSN_BENCH_STOP_AND_PRINT \
00103 { \
00104 v_benchers.back()->stop(); \
00105 std::cerr << std::string(n_bench_indent, ' ') << \
00106 __FUNCTION__ << ": " << \
00107 v_benchers.back()->get_time() << std::endl; \
00108 n_bench_indent -= 3; \
00109 std::cerr << std::string(n_bench_indent, ' ') << \
00110 "Stop bench in " << __FUNCTION__ << "..." << std::endl; \
00111 delete v_benchers.back(); \
00112 v_benchers.pop_back(); \
00113 }
00114 }
00115 }
00116
00117
00118
00119 # ifndef VCSN_USE_INTERFACE_ONLY
00120 # include <vaucanson/tools/bencher.hxx>
00121 # endif // VCSN_USE_INTERFACE_ONLY
00122
00123 # else // VCSN_BENCH
00124
00125 # define VCSN_BENCH_START
00126 # define VCSN_BENCH_STOP
00127 # define VCSN_BENCH_PRINT
00128 # define VCSN_BENCH_STOP_AND_PRINT
00129 # define VCSN_BENCH_START_QUIET
00130 # define VCSN_BENCH_STOP_QUIET
00131
00132 # endif // ! VCSN_BENCH
00133 #endif // ! VCSN_TOOLS_BENCHER_HH