bencher.hh

00001 // bencher.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004, 2005, 2006, 2007 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
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   } // tools
00059 } // vcsn
00060 
00061 #  define VCSN_BENCH_START_QUIET                \
00062   {                                             \
00063     using namespace vcsn::tools;                \
00064     v_benchers.push_back(new bencher);          \
00065     v_benchers.back()->start();                 \
00066   }
00067 
00068 #  define VCSN_BENCH_START                                      \
00069   {                                                             \
00070     using namespace vcsn::tools;                                \
00071     v_benchers.push_back(new bencher);                          \
00072     v_benchers.back()->start();                                 \
00073     std::cerr << std::string(n_bench_indent, ' ') <<            \
00074       "Start bench in " << __FUNCTION__ << "..." << std::endl;  \
00075     n_bench_indent += 3;                                        \
00076   }
00077 
00078 #  define VCSN_BENCH_STOP_QUIET(Result)         \
00079   {                                             \
00080     using namespace vcsn::tools;                \
00081     v_benchers.back()->stop();                  \
00082     Result = v_benchers.back()->get_time();     \
00083     delete v_benchers.back();                   \
00084     v_benchers.pop_back();                      \
00085   }
00086 
00087 #  define VCSN_BENCH_STOP                                               \
00088   {                                                                     \
00089     using namespace vcsn::tools;                                        \
00090     v_benchers.back()->stop();                                          \
00091     v_old_benchers.insert(v_old_benchers.begin(),                       \
00092                           std::pair<int, bencher*>(n_bench_indent,      \
00093                                                    v_benchers.back())); \
00094     n_bench_indent -= 3;                                                \
00095     std::cerr << std::string(n_bench_indent, ' ') <<                    \
00096       "Stop bench in " << __FUNCTION__ << "..." << std::endl;           \
00097     v_benchers.pop_back();                                              \
00098   }
00099 
00100 #  define VCSN_BENCH_PRINT                                              \
00101   {                                                                     \
00102     using namespace vcsn::tools;                                        \
00103     std::cerr << std::string(v_old_benchers.back().first, ' ') <<       \
00104       __FUNCTION__ << ": " <<                                           \
00105       v_old_benchers.back().second->get_time() << std::endl;            \
00106     delete v_old_benchers.back().second;                                \
00107     v_old_benchers.pop_back();                                          \
00108   }
00109 
00110 #  define VCSN_BENCH_STOP_AND_PRINT                             \
00111   {                                                             \
00112     using namespace vcsn::tools;                                \
00113     v_benchers.back()->stop();                                  \
00114     std::cerr << std::string(n_bench_indent, ' ') <<            \
00115       __FUNCTION__ << ": " <<                                   \
00116       v_benchers.back()->get_time() << std::endl;               \
00117     n_bench_indent -= 3;                                        \
00118     std::cerr << std::string(n_bench_indent, ' ') <<            \
00119       "Stop bench in " << __FUNCTION__ << "..." << std::endl;   \
00120     delete v_benchers.back();                                   \
00121     v_benchers.pop_back();                                      \
00122   }
00123 
00124 
00125 
00126 #  ifndef VCSN_USE_INTERFACE_ONLY
00127 #   include <vaucanson/tools/bencher.hxx>
00128 #  endif // VCSN_USE_INTERFACE_ONLY
00129 
00130 # else // VCSN_BENCH
00131 
00132 #  define VCSN_BENCH_START
00133 #  define VCSN_BENCH_STOP
00134 #  define VCSN_BENCH_PRINT
00135 #  define VCSN_BENCH_STOP_AND_PRINT
00136 #  define VCSN_BENCH_START_QUIET
00137 #  define VCSN_BENCH_STOP_QUIET
00138 
00139 # endif // ! VCSN_BENCH
00140 #endif // ! VCSN_TOOLS_BENCHER_HH

Generated on Thu Oct 9 20:22:33 2008 for Vaucanson by  doxygen 1.5.1