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