diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-27 03:34:51 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-27 03:34:51 +0400 |
commit | 7093d2e2cd0ec361665a1cd8eb7668573b509316 (patch) | |
tree | 47148985ed1cb355d67578914e2eae2afc7d9492 /mert/TimerTest.cpp | |
parent | 3b47348550d485b34b8db3b03a749f7aba6ef86d (diff) |
Change mert/Timer.
- Add a high resolution timing function to measure the
wall-clock time by gettimeofday().
- Now the Timer class use getrusage() to measure the elapsed
CPU time as KenLM does.
- Revive Timer::restart().
- Add Timer::ToString() for reporting the detail statistics
as well as for debugging.
- Add a simple unit test for Timer.
Diffstat (limited to 'mert/TimerTest.cpp')
-rw-r--r-- | mert/TimerTest.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mert/TimerTest.cpp b/mert/TimerTest.cpp new file mode 100644 index 000000000..04ec75dfa --- /dev/null +++ b/mert/TimerTest.cpp @@ -0,0 +1,27 @@ +#include "Timer.h" + +#define BOOST_TEST_MODULE TimerTest +#include <boost/test/unit_test.hpp> + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_CASE(timer_basic_test) { + Timer timer; + timer.start(); + BOOST_REQUIRE(timer.is_running()); + BOOST_REQUIRE(timer.get_elapsed_cpu_time() > 0.0); + BOOST_REQUIRE(timer.get_elapsed_cpu_time_microseconds() > 0); + BOOST_REQUIRE(timer.get_elapsed_wall_time() > 0.0); + BOOST_REQUIRE(timer.get_elapsed_wall_time_microseconds() > 0); + + timer.restart(); + BOOST_REQUIRE(timer.is_running()); + BOOST_REQUIRE(timer.get_elapsed_cpu_time() > 0.0); + BOOST_REQUIRE(timer.get_elapsed_cpu_time_microseconds() > 0); + BOOST_REQUIRE(timer.get_elapsed_wall_time() > 0.0); + BOOST_REQUIRE(timer.get_elapsed_wall_time_microseconds() > 0); + + const std::string s = timer.ToString(); + BOOST_REQUIRE(!s.empty()); +} |