Some common benchmarking tools added
authorAlpar Juttner <alpar@cs.elte.hu>
Sun, 11 Dec 2011 07:33:29 +0100
changeset 10d7ce0311ece2
parent 9 7768d68909e8
child 11 cf6519daa7fa
Some common benchmarking tools added
tests/CMakeLists.txt
tests/benchmark_tools.h
tests/circulation.cc
tests/main.cc
     1.1 --- a/tests/CMakeLists.txt	Sun Dec 11 06:55:47 2011 +0100
     1.2 +++ b/tests/CMakeLists.txt	Sun Dec 11 07:33:29 2011 +0100
     1.3 @@ -8,7 +8,7 @@
     1.4  )
     1.5  
     1.6  ADD_EXECUTABLE(circulation
     1.7 -        circulation.cc
     1.8 +        circulation.cc main.cc
     1.9  )
    1.10  
    1.11  TARGET_LINK_LIBRARIES(circulation
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/benchmark_tools.h	Sun Dec 11 07:33:29 2011 +0100
     2.3 @@ -0,0 +1,21 @@
     2.4 +#ifndef BENCHMARK_TOOLS_H
     2.5 +#define BENCHMARK_TOOLS_H
     2.6 +
     2.7 +#include<string>
     2.8 +#include<iostream>
     2.9 +#include<iomanip>
    2.10 +#include<lemon/time_measure.h>
    2.11 +
    2.12 +extern const char test_name[];
    2.13 +
    2.14 +inline void logTime(const std::string &subtest_name, const
    2.15 +                    lemon::TimeStamp &time)
    2.16 +{
    2.17 +  std::cout << "*** " << test_name << ' ' << subtest_name << ' '
    2.18 +	    << std::setiosflags(std::ios::fixed) << std::setprecision(4)
    2.19 +	    << time.realTime() << ' '
    2.20 +            << time.realTime()/(time.userTime()+time.systemTime()) - 1.0
    2.21 +            << std::endl;
    2.22 +}
    2.23 +
    2.24 +#endif
     3.1 --- a/tests/circulation.cc	Sun Dec 11 06:55:47 2011 +0100
     3.2 +++ b/tests/circulation.cc	Sun Dec 11 07:33:29 2011 +0100
     3.3 @@ -1,15 +1,15 @@
     3.4 +#include <benchmark_tools.h>
     3.5  #include <lemon/circulation.h>
     3.6  #include <lemon/smart_graph.h>
     3.7  #include <lemon/lgf_reader.h>
     3.8  #include <lemon/dimacs.h>
     3.9 -#include <lemon/time_measure.h>
    3.10  #include <lemon/error.h>
    3.11  
    3.12  const char test_name[] = "circulation";
    3.13  
    3.14  using namespace lemon;
    3.15  
    3.16 -int main(int argc, char **argv)
    3.17 +int testMain(int argc, char **argv)
    3.18  {
    3.19    if(argc!=2) exit(1);
    3.20  
    3.21 @@ -31,36 +31,41 @@
    3.22      std::cerr << error.what() << std::endl;
    3.23      return 1;
    3.24    }
    3.25 -  std::cerr << "Read the file: " << ti << '\n';
    3.26 +  logTime("file-read",ti);
    3.27 +
    3.28 +  Timer tf;
    3.29    ti.restart();
    3.30 -  
    3.31    Circulation<SmartDigraph,
    3.32      SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
    3.33      SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
    3.34 -  std::cerr << "Setup Circulation class: " << ti << '\n';
    3.35 +  logTime("setup",ti);
    3.36    ti.restart();
    3.37    bool res = circ.run();
    3.38 +  logTime("alg",ti);
    3.39 +  logTime("full",tf);
    3.40    if(res)
    3.41      {
    3.42 -      std::cerr << "A feasible circulation is found: " << ti << "\n";
    3.43 +      std::cerr << "A feasible circulation is found\n";
    3.44 +      std::cerr << "Checking...\n";
    3.45        ti.restart();
    3.46        bool res2 = circ.checkFlow();
    3.47 -      std::cerr << "Checked in time " << ti << "\n";
    3.48 +      logTime("check",ti);
    3.49        if(res2)
    3.50 -        std::cerr << "Success!\nn";
    3.51 +        std::cerr << "Success!\n";
    3.52        else
    3.53 -        std::cerr << "Oops!!!!\n\n";
    3.54 +        std::cerr << "Oops!!!!\n";
    3.55      }
    3.56    else
    3.57      {
    3.58 -      std::cerr << "A dual solution is found: " << ti << "\n";
    3.59 +      std::cerr << "A dual solution is found\n";
    3.60 +      std::cerr << "Checking...\n";
    3.61        ti.restart();
    3.62        bool res2 = circ.checkBarrier();
    3.63 -      std::cerr << "Checked in time " << ti << "\n";
    3.64 +      logTime("check",ti);
    3.65        if(res2)
    3.66 -        std::cerr << "Success!\nn";
    3.67 +        std::cerr << "Success!\n";
    3.68        else
    3.69 -        std::cerr << "Dual-Oops!!!!\n\n";
    3.70 +        std::cerr << "Dual-Oops!!!!\n";
    3.71  
    3.72      }
    3.73  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tests/main.cc	Sun Dec 11 07:33:29 2011 +0100
     4.3 @@ -0,0 +1,12 @@
     4.4 +#include <benchmark_tools.h>
     4.5 +
     4.6 +using namespace lemon;
     4.7 +
     4.8 +int testMain(int argc, char **argv);
     4.9 +
    4.10 +int main(int argc, char **argv)
    4.11 +{
    4.12 +  Timer ti;
    4.13 +  testMain(argc, argv);
    4.14 +  logTime("total",ti);
    4.15 +}