Commit e2ae22f3 authored by Florent D'Halluin's avatar Florent D'Halluin Committed by Alexandre Duret-Lutz
Browse files

Equip bench with CBS

3 Steps:

1) Use CBS files.
2) Remove obsolete tools.
3) Equip all benches.

1) Use CBS files:

* src/bench/common/bench_macros.hh: New.
Include cbs/bench/bench.hh, define handy macros.
* src/bench/common/Makefile.am: Add file.
* src/bench/generate_bench.sh: Include common/bench_macros.hh in
generated Makefiles.

2) Remove obsolete tools:

* include/vaucanson/tools/bencher.hh,
* include/vaucanson/tools/bencher.hxx: Deleted.
Served the same purpose as the cbs timer, with less flexibility.
* include/vaucanson/Makefile.am: Remove files.

3) Equip all benches:

Replace macros VCSN_BENCH_XXX with the CBS equivalent.
Add parameters and results when applicable (all the info
previously printed on cout/cerr are now parameters and results).

3 files are generated for each bench.  There are between 5 and 10
benches per file below.  See common/bench_macros.hh to change that.

* src/bench/composition/normalized_composition_bench.hh,
* src/bench/composition/rw_composition_bench.hh,
* src/bench/derived_terms/derived_terms_bench.hh,
* src/bench/determinization/determinization_bench.hh,
* src/bench/eps_removal/eps_removal_bench.hh,
* src/bench/iterators/accessible_bench.hh,
* src/bench/iterators/iterator_bench.hh,
* src/bench/minimization_2n/minimization_2n_brzozowski_bench.h,
* src/bench/minimization_2n/minimization_2n_hopcroft_bench.hh,
* src/bench/minimization_2n/minimization_2n_moore_bench.hh,
* src/bench/minimization_debruijn/minimization_debruijn_brzozo,
* src/bench/minimization_debruijn/minimization_debruijn_hopcro,
* src/bench/minimization_debruijn/minimization_debruijn_moore_,
* src/bench/quotient/quotient_bool_bench.hh,
* src/bench/quotient/quotient_z_bench.hh: Do that.
parent dd25051c
......@@ -5,7 +5,16 @@
CBS version: e97a404a44e5b5d19d4a869aa1f43524386c5b09.
See cbs/Changelog.
 
2009-04-11 d-halluin <d-halluin@lrde.epita.fr>
2009-04-10 d-halluin <d-halluin@lrde.epita.fr>
Link taf-kit, libs and benches with $(benchlib).
* vaucanson.mk: Define benchlib.
* lib/generate_libvcsn.rb,
* taf-kit/src/Makefile.am,
* src/bench/generate_bench.sh: Use it.
2009-04-10 d-halluin <d-halluin@lrde.epita.fr>
 
Replace timer and global_timer with cbs.
 
......@@ -106,6 +115,57 @@
* include/vaucanson/tools/io.hxx: Replace TIMER_SCOPED with
BENCH_TASK_SCOPED.
 
2009-04-11 d-halluin <d-halluin@lrde.epita.fr>
Equip bench with CBS
Note: Squash previous related patches with this one.
3 Steps:
1) Use CBS files.
2) Remove obsolete tools.
3) Equip all benches.
1) Use CBS files:
* src/bench/common/bench_macros.hh: New.
Include cbs/bench/bench.hh, define handy macros.
* src/bench/common/Makefile.am: Add file.
* src/bench/generate_bench.sh: Include common/bench_macros.hh in
generated Makefiles.
2) Remove obsolete tools:
* include/vaucanson/tools/bencher.hh,
* include/vaucanson/tools/bencher.hxx: Deleted.
Served the same purpose as the cbs timer, with less flexibility.
3) Equip all benches:
Replace macros VCSN_BENCH_XXX with the CBS equivalent.
Add parameters and results when applicable (all the info
previously printed on cout/cerr are now parameters and results).
3 files are generated for each bench. There are between 5 and 10
benches per file below. See common/bench_macros.hh to change that.
* src/bench/composition/normalized_composition_bench.hh,
* src/bench/composition/rw_composition_bench.hh,
* src/bench/derived_terms/derived_terms_bench.hh,
* src/bench/determinization/determinization_bench.hh,
* src/bench/eps_removal/eps_removal_bench.hh,
* src/bench/iterators/accessible_bench.hh,
* src/bench/iterators/iterator_bench.hh,
* src/bench/minimization_2n/minimization_2n_brzozowski_bench.h,
* src/bench/minimization_2n/minimization_2n_hopcroft_bench.hh,
* src/bench/minimization_2n/minimization_2n_moore_bench.hh,
* src/bench/minimization_debruijn/minimization_debruijn_brzozo,
* src/bench/minimization_debruijn/minimization_debruijn_hopcro,
* src/bench/minimization_debruijn/minimization_debruijn_moore_,
* src/bench/quotient/quotient_bool_bench.hh,
* src/bench/quotient/quotient_z_bench.hh: Do that.
2009-04-06 d-halluin <d-halluin@lrde.epita.fr>
 
Add cbs (libbench).
......
......@@ -100,8 +100,6 @@ vaucanson/misc/window.hxx
nobase_include_HEADERS += \
vaucanson/tools/automaton_tools.hh \
vaucanson/tools/bencher.hh \
vaucanson/tools/bencher.hxx \
vaucanson/tools/dot_display.hh \
vaucanson/tools/dot_display.hxx \
vaucanson/tools/dot_dump.hh \
......
// bencher.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2004, 2005, 2006, 2007 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef VCSN_TOOLS_BENCHER_HH
# define VCSN_TOOLS_BENCHER_HH
# ifdef VCSN_BENCH
# include <sys/time.h>
# include <sys/resource.h>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <ctime>
# include <iostream>
# include <vector>
# include <string>
# include <utility>
namespace vcsn
{
namespace tools
{
class bencher {
public:
bencher();
~bencher();
public:
void start();
void stop();
double get_time();
private:
double dtime();
double start_;
double stop_;
};
unsigned int n_bench_indent;
std::vector<bencher*> v_benchers;
std::vector< std::pair<int, bencher*> > v_old_benchers;
} // tools
} // vcsn
# define VCSN_BENCH_START_QUIET \
{ \
using namespace vcsn::tools; \
v_benchers.push_back(new bencher); \
v_benchers.back()->start(); \
}
# define VCSN_BENCH_START \
{ \
using namespace vcsn::tools; \
v_benchers.push_back(new bencher); \
v_benchers.back()->start(); \
std::cerr << std::string(n_bench_indent, ' ') << \
"Start bench in " << __FUNCTION__ << "..." << std::endl; \
n_bench_indent += 3; \
}
# define VCSN_BENCH_STOP_QUIET(Result) \
{ \
using namespace vcsn::tools; \
v_benchers.back()->stop(); \
Result = v_benchers.back()->get_time(); \
delete v_benchers.back(); \
v_benchers.pop_back(); \
}
# define VCSN_BENCH_STOP \
{ \
using namespace vcsn::tools; \
v_benchers.back()->stop(); \
v_old_benchers.insert(v_old_benchers.begin(), \
std::pair<int, bencher*>(n_bench_indent, \
v_benchers.back())); \
n_bench_indent -= 3; \
std::cerr << std::string(n_bench_indent, ' ') << \
"Stop bench in " << __FUNCTION__ << "..." << std::endl; \
v_benchers.pop_back(); \
}
# define VCSN_BENCH_PRINT \
{ \
using namespace vcsn::tools; \
std::cerr << std::string(v_old_benchers.back().first, ' ') << \
__FUNCTION__ << ": " << \
v_old_benchers.back().second->get_time() << std::endl; \
delete v_old_benchers.back().second; \
v_old_benchers.pop_back(); \
}
# define VCSN_BENCH_STOP_AND_PRINT \
{ \
using namespace vcsn::tools; \
v_benchers.back()->stop(); \
std::cerr << std::string(n_bench_indent, ' ') << \
__FUNCTION__ << ": " << \
v_benchers.back()->get_time() << std::endl; \
n_bench_indent -= 3; \
std::cerr << std::string(n_bench_indent, ' ') << \
"Stop bench in " << __FUNCTION__ << "..." << std::endl; \
delete v_benchers.back(); \
v_benchers.pop_back(); \
}
# ifndef VCSN_USE_INTERFACE_ONLY
# include <vaucanson/tools/bencher.hxx>
# endif // VCSN_USE_INTERFACE_ONLY
# else // VCSN_BENCH
# define VCSN_BENCH_START
# define VCSN_BENCH_STOP
# define VCSN_BENCH_PRINT
# define VCSN_BENCH_STOP_AND_PRINT
# define VCSN_BENCH_START_QUIET
# define VCSN_BENCH_STOP_QUIET
# endif // ! VCSN_BENCH
#endif // ! VCSN_TOOLS_BENCHER_HH
EXTRA_DIST = alpha.syms bench_automaton.hh \
bench_constructs.hh bench.mk
EXTRA_DIST = alpha.syms bench_automaton.hh \
bench_constructs.hh bench.mk \
bench_macros.hh
test:
echo hella
// bencher.hxx: this file is part of the Vaucanson project.
// bench_macros.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2004, 2005, 2007 The Vaucanson Group.
// Copyright (C) 2005, 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -14,50 +14,22 @@
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef VCSN_TOOLS_BENCHER_HXX
# define VCSN_TOOLS_BENCHER_HXX
# include <vaucanson/tools/bencher.hh>
#ifndef VCSN_BENCHS_COMMON_BENCH_MACROS_HH
# define VCSN_BENCHS_COMMON_BENCH_MACROS_HH
# ifdef VCSN_BENCH
# include <cbs/bench/bench_macros.hh>
namespace vcsn
{
namespace tools
{
# define BENCH_VCSN_SAVE_AND_PRINT(Name) \
BENCH_SAVE(Name + ".xml", bench::Options()); \
BENCH_SAVE(Name + ".out", bench::Options(bench::Options::VE_MINIMAL, \
bench::Options::FO_TEXT)); \
BENCH_SAVE(Name + ".dot", bench::Options(bench::Options::VE_NORMAL, \
bench::Options::FO_DOT, \
0)); \
BENCH_PRINT(bench::Options(bench::Options::VE_NORMAL, \
bench::Options::FO_TEXT, \
0));
bencher::bencher() : start_(0), stop_(0)
{}
bencher::~bencher()
{}
void bencher::start()
{
start_ = dtime();
}
void bencher::stop()
{
stop_ = dtime();
}
double bencher::get_time()
{
return stop_ - start_;
}
double bencher::dtime()
{
rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return ((double)(rusage.ru_utime.tv_sec)
+ (double)(rusage.ru_utime.tv_usec) * 1.0e-06);
}
}
}
# endif // ! VCSN_BENCH
#endif // ! VCSN_TOOLS_BENCHER_HXX
#endif // ! VCSN_BENCHS_COMMON_BENCH_MACROS_HH
......@@ -14,7 +14,6 @@
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#include <vaucanson/tools/bencher.hh>
#include <vaucanson/algorithms/normalized_composition.hh>
#include <vaucanson/algorithms/sub_normalize.hh>
......@@ -136,8 +135,6 @@ void normalized_composition_bench(int n_value)
to += "a";
}
VCSN_BENCH_START;
automaton_t left_auto = replace_left(from, to, A, B);
fmp_transducer::automaton_t fmp_left_auto =
......@@ -145,41 +142,55 @@ void normalized_composition_bench(int n_value)
fmp_transducer::automaton_t sub_left_auto =
fmp_transducer::make_automaton(A,B);
std::cerr << "Left sub-normalisation" << std::endl;
VCSN_BENCH_START;
rw_to_fmp(left_auto, fmp_left_auto);
sub_normalize(fmp_left_auto, sub_left_auto);
std::cout << "nb states: " << sub_left_auto.states().size() << std::endl;
std::cout << "nb transitions: " << sub_left_auto.transitions().size() << std::endl;
VCSN_BENCH_STOP_AND_PRINT;
automaton_t right_auto = replace_right(from, to, B, C);
automaton_t right_auto = replace_right(from, to, B, C);
fmp_transducer::automaton_t fmp_right_auto =
fmp_transducer::make_automaton(B,C);
fmp_transducer::automaton_t sub_right_auto =
fmp_transducer::make_automaton(B,C);
std::cerr << "Right sub-normalisation" << std::endl;
VCSN_BENCH_START;
rw_to_fmp(right_auto, fmp_right_auto);
sub_normalize(fmp_right_auto, sub_right_auto);
std::cout << "nb states: " << sub_right_auto.states().size() << std::endl;
std::cout << "nb transitions: " << sub_right_auto.transitions().size()
<< std::endl;
VCSN_BENCH_STOP_AND_PRINT;
std::cerr << "Normalized composition" << std::endl;
VCSN_BENCH_START;
std::stringstream n_value_str;
n_value_str << n_value;
BENCH_START("Normalized composition", "Vaucanson - normalized composition");
{
BENCH_TASK_SCOPED("Left sub-normalisation");
rw_to_fmp(left_auto, fmp_left_auto);
sub_normalize(fmp_left_auto, sub_left_auto);
}
{
BENCH_TASK_SCOPED("Right sub-normalisation");
rw_to_fmp(right_auto, fmp_right_auto);
sub_normalize(fmp_right_auto, sub_right_auto);
}
fmp_transducer::automaton_t res_auto = fmp_transducer::make_automaton(A,C);
u_compose(sub_left_auto, sub_right_auto, res_auto);
{
BENCH_TASK_SCOPED("Composition");
u_compose(sub_left_auto, sub_right_auto, res_auto);
}
BENCH_STOP();
// Set extra parameters/results
BENCH_RESULT("sub left states", (long) sub_left_auto.states().size());
BENCH_RESULT("sub left transitions",
(long) sub_left_auto.transitions().size());
BENCH_RESULT("sub right states", (long) sub_right_auto.states().size());
BENCH_RESULT("sub right transitions",
(long) sub_right_auto.transitions().size());
BENCH_RESULT("states", (long) res_auto.states().size());
BENCH_RESULT("transitions", (long) res_auto.transitions().size());
std::cout << "nb states: " << res_auto.states().size() << std::endl;
std::cout << "nb transitions: " << res_auto.transitions().size()
<< std::endl;
std::string name = "bench_normalized_composition_" + n_value_str.str();
VCSN_BENCH_STOP_AND_PRINT;
VCSN_BENCH_STOP_AND_PRINT;
// Save and print
BENCH_VCSN_SAVE_AND_PRINT(name);
}
......@@ -14,7 +14,6 @@
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#include <vaucanson/tools/bencher.hh>
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/boolean_transducer.hh>
......@@ -133,19 +132,29 @@ void rw_composition_bench(int n_value)
to += "a";
}
VCSN_BENCH_START;
std::stringstream n_value_str;
n_value_str << n_value;
BENCH_START("rw_composition", "Vaucanson - rw composition");
automaton_t left_auto = replace_left(from, to, A, B);
std::cout << "left nb states: " << left_auto.states().size() << std::endl;
std::cout << "left nb transitions: " << left_auto.transitions().size()
<< std::endl;
automaton_t right_auto = replace_right(from, to, B, C);
std::cout << "right nb states: " << right_auto.states().size() << std::endl;
std::cout << "right nb transitions: " << right_auto.transitions().size()
<< std::endl;
automaton_t res_auto = make_automaton(A, C);
rw_composition(left_auto, right_auto, res_auto);
std::cout << "nb states: " << res_auto.states().size() << std::endl;
std::cout << "nb transitions: " << res_auto.transitions().size() << std::endl;
VCSN_BENCH_STOP_AND_PRINT;
BENCH_STOP();
// Set extra parameters/results
BENCH_RESULT("left states", (long) left_auto.states().size());
BENCH_RESULT("left transitions", (long) left_auto.transitions().size());
BENCH_RESULT("right states", (long) right_auto.states().size());
BENCH_RESULT("right transitions",(long) right_auto.states().size());
BENCH_RESULT("states", (long) res_auto.states().size());
BENCH_RESULT("transitions", (long) res_auto.states().size());
std::string name = "bench_rw_composition_" + n_value_str.str();
// Save and print
BENCH_VCSN_SAVE_AND_PRINT(name);
}
......@@ -33,6 +33,7 @@ using namespace vcsn;
using namespace vcsn::boolean_automaton;
#include <common/bench_constructs.hh>
#include <cbs/bench/timer.hh>
struct Data
{
......@@ -72,41 +73,53 @@ void derived_terms_bench(int n_states)
automaton_t a = make_automaton(alpha);
aut_2n(n_states, a);
BENCH_START("derived terms",
"Vaucanson - derived terms.\n"
"Times in ms.");
// Get all data.
for (int i = 0; i < SAMPLES; ++i)
{
Data data;
krat_t e = aut_to_exp(a, chooser);
timer::Timer timer;
// Get derived terms automaton of e.
data.n_len = e.value(). length();
automaton_t dt = make_automaton(alpha);
VCSN_BENCH_START_QUIET;
timer.start();
derived_term_automaton(dt, e);
VCSN_BENCH_STOP_QUIET(data.r_time_dt);
timer.stop();
data.r_time_dt = (double) timer.time();
data.n_dt_states = dt.states().size();
data.n_dt_transitions = dt.transitions().size();
// Get standart automaton of e.
VCSN_BENCH_START_QUIET;
timer.start();
automaton_t so = standard_of(e);
VCSN_BENCH_STOP_QUIET(data.r_time_so);
timer.stop();
data.r_time_so = (double) timer.time();
data.n_so_transitions = so.transitions().size();
// Minimize dt.
VCSN_BENCH_START_QUIET;
timer.start();
automaton_t q = quotient(dt);
VCSN_BENCH_STOP_QUIET(data.r_time_quot_dt);
timer.stop();
data.r_time_quot_dt = (double) timer.time();
data.n_min_states = q.states().size();
data.n_min_transitions = q.transitions().size();
// Minimize so.
VCSN_BENCH_START_QUIET;
timer.start();
quotient(so);
VCSN_BENCH_STOP_QUIET(data.r_time_quot_so);
timer.stop();
data.r_time_quot_so = (double) timer.time();
datas[i] = data;
}
BENCH_STOP();
sort(datas.begin(), datas.end(), Data());
// Summarize all data.
......@@ -147,17 +160,33 @@ void derived_terms_bench(int n_states)
n_dt_transitions /= SAMPLES_PER_CLASS;
n_so_transitions /= SAMPLES_PER_CLASS;
n_min_transitions /= SAMPLES_PER_CLASS;
std::cerr << "Class " << i + 1 << std::endl
<< "Average length: " << n_len << std::endl
<< "Average dt time: " << r_time_dt << std::endl
<< "Average so time: " << r_time_so << std::endl
<< "Average dt states: " << n_dt_states << std::endl
<< "Average dt transitions: " << n_dt_transitions << std::endl
<< "Average so transitions: " << n_so_transitions << std::endl
<< "Average quot time on dt: " << r_time_quot_dt << std::endl
<< "Average quot time on so: " << r_time_quot_so << std::endl
<< "Average min states: " << n_min_states << std::endl
<< "Average min transitions: " << n_min_transitions << std::endl;
std::stringstream class_str;
class_str << i + 1;
std::string prefix = "[" + class_str.str() + "] ";
BENCH_RESULT(prefix + "average length", (long) n_len);
BENCH_RESULT(prefix + "average dt time", (double) r_time_dt);
BENCH_RESULT(prefix + "average so time", (double) r_time_so);
BENCH_RESULT(prefix + "average dt states", (long) n_dt_states);
BENCH_RESULT(prefix + "average dt transitions", (long) n_dt_transitions);
BENCH_RESULT(prefix + "average so transitions", (long) n_so_transitions);
BENCH_RESULT(prefix + "average quot time on dt", (double) r_time_quot_dt);
BENCH_RESULT(prefix + "average quot time on so", (double) r_time_quot_so);
BENCH_RESULT(prefix + "average min states", (long) n_min_states);
BENCH_RESULT(prefix + "average min transitions", (long) n_min_transitions);
}
BENCH_PARAMETER("classes", (long) CLASSES);
BENCH_PARAMETER("samples per class", (long) SAMPLES_PER_CLASS);
BENCH_PARAMETER("samples", (long) SAMPLES);
BENCH_PARAMETER("n_states", (long) n_states);
std::stringstream name;
name << "bench_derived_terms_" << n_states;
BENCH_VCSN_SAVE_AND_PRINT(name.str());
}
......@@ -14,6 +14,8 @@
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/algorithms/determinize.hh>
#include <iostream>
......@@ -36,8 +38,18 @@ void determinization_bench(int n_states)
alpha.insert('c');
automaton_t a = make_automaton(alpha);
aut_2n(n_states, a);
VCSN_BENCH_START;
BENCH_START("determinize", "Vaucanson - determinization.");
automaton_t ret = determinize(a);
VCSN_BENCH_STOP_AND_PRINT;
BENCH_STOP();
BENCH_PARAMETER("n_states", (long) n_states);
std::stringstream name;
name << "bench_determinize_" << n_states;
BENCH_VCSN_SAVE_AND_PRINT(name.str());
}
......@@ -41,8 +41,13 @@ void eps_removal_bench(int n_states)
automaton_t a = make_automaton(alpha);
aut_linear_eps(n_states, a);
VCSN_BENCH_START;
BENCH_START("eps removal", "Vaucanson - eps removal.");
automaton_t ret = eps_removal(a);
VCSN_BENCH_STOP_AND_PRINT;
}
BENCH_STOP();