[Groonga-commit] groonga/grnxx [master] Update tests to use grnxx::Stopwatch.

Back to archive index

susumu.yata null+****@clear*****
Thu Feb 28 14:32:59 JST 2013


susumu.yata	2013-02-28 14:32:59 +0900 (Thu, 28 Feb 2013)

  New Revision: b11d78fa7665467c411cfba4a6e1771f9854a4b6
  https://github.com/groonga/grnxx/commit/b11d78fa7665467c411cfba4a6e1771f9854a4b6

  Log:
    Update tests to use grnxx::Stopwatch.

  Modified files:
    test/test_broken_down_time.cpp
    test/test_db_blob_vector.cpp
    test/test_db_vector.cpp
    test/test_intrinsic.cpp
    test/test_io_pool.cpp
    test/test_mutex.cpp
    test/test_recycler.cpp
    test/test_string.cpp
    test/test_string_format.cpp
    test/test_thread.cpp
    test/test_time.cpp

  Modified: test/test_broken_down_time.cpp (+5 -7)
===================================================================
--- test/test_broken_down_time.cpp    2013-02-28 14:18:11 +0900 (528bf5b)
+++ test/test_broken_down_time.cpp    2013-02-28 14:32:59 +0900 (85bfd3c)
@@ -18,7 +18,7 @@
 #include <cassert>
 
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 #include "system_clock.hpp"
 
 int main() {
@@ -35,21 +35,19 @@ int main() {
 
   grnxx::Time now = grnxx::SystemClock::now();
 
-  grnxx::Time start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {
     now.universal_time();
   }
-  grnxx::Time end = grnxx::SteadyClock::now();
-  grnxx::Duration elapsed = end - start;
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::Time::universal_time(): average elapsed [ns] = "
                  << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < LOOP_COUNT; ++i) {
     now.local_time();
   }
-  end = grnxx::SteadyClock::now();
-  elapsed = end - start;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::Time::local_time(): average elapsed [ns] = "
                  << (1000.0 * elapsed.count() / LOOP_COUNT);
 

  Modified: test/test_db_blob_vector.cpp (+5 -5)
===================================================================
--- test/test_db_blob_vector.cpp    2013-02-28 14:18:11 +0900 (04234f0)
+++ test/test_db_blob_vector.cpp    2013-02-28 14:32:59 +0900 (3c7bf4f)
@@ -22,7 +22,7 @@
 
 #include "db/blob_vector.hpp"
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 void test_basics() {
   grnxx::io::Pool::unlink_if_exists("temp.grn");
@@ -361,27 +361,27 @@ void test_defrag() {
     vector[ids[i]].set(&value[0], length);
   }
 
-  grnxx::Time start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (std::uint32_t i = 0; i < NUM_VALUES; ++i) {
     grnxx::db::Blob blob = vector[i];
     if (blob.length() > 0) {
       assert(*static_cast<const char *>(blob.address()) == 'X');
     };
   }
-  grnxx::Duration elapsed = grnxx::SteadyClock::now() - start;
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "before defrag: elapsed [ns] = "
                  << (elapsed.count() * 1000 / NUM_VALUES);
 
   vector.defrag();
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < NUM_VALUES; ++i) {
     grnxx::db::Blob blob = vector[i];
     if (blob.length() > 0) {
       assert(*static_cast<const char *>(blob.address()) == 'X');
     };
   }
-  elapsed = grnxx::SteadyClock::now() - start;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "after defrag: elapsed [ns] = "
                  << (elapsed.count() * 1000 / NUM_VALUES);
 }

  Modified: test/test_db_vector.cpp (+23 -36)
===================================================================
--- test/test_db_vector.cpp    2013-02-28 14:18:11 +0900 (0f146d8)
+++ test/test_db_vector.cpp    2013-02-28 14:32:59 +0900 (45152e9)
@@ -22,7 +22,7 @@
 
 #include "db/vector.hpp"
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 struct Point {
   double x;
@@ -190,55 +190,47 @@ void test_times() {
 
   grnxx::db::Vector<T> vector(grnxx::db::VECTOR_CREATE, pool);
 
-  grnxx::Time start, end;
-
   std::uint64_t total = 0;
 
-  start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (std::uint64_t id = 0; id < VECTOR_SIZE; ++id) {
     vector[id] = T(0);
   }
-  end = grnxx::SteadyClock::now();
-  double set_1st_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double set_1st_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = 0; id < VECTOR_SIZE; ++id) {
     vector[id] = T(1);
   }
-  end = grnxx::SteadyClock::now();
-  double set_2nd_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double set_2nd_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = 0; id < VECTOR_SIZE; ++id) {
     total += vector[id];
   }
-  end = grnxx::SteadyClock::now();
-  double get_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double get_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = vector.max_id() - VECTOR_SIZE + 1;
        id <= vector.max_id(); ++id) {
     vector[id] = T(0);
   }
-  end = grnxx::SteadyClock::now();
-  double ex_set_1st_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double ex_set_1st_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = vector.max_id() - VECTOR_SIZE + 1;
        id <= vector.max_id(); ++id) {
     vector[id] = T(1);
   }
-  end = grnxx::SteadyClock::now();
-  double ex_set_2nd_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double ex_set_2nd_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = vector.max_id() - VECTOR_SIZE + 1;
        id <= vector.max_id(); ++id) {
     total += vector[id];
   }
-  end = grnxx::SteadyClock::now();
-  double ex_get_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double ex_get_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
 
   const std::uint64_t boundary = vector.page_size() * vector.table_size();
@@ -256,46 +248,41 @@ void test_times() {
     ids[i] = id_begin + (engine() % range);
   }
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < VECTOR_SIZE; ++i) {
     vector[ids[i]] = T(0);
   }
-  end = grnxx::SteadyClock::now();
   double boundary_set_1st_elapsed =
-      1000.0 * (end - start).count() / VECTOR_SIZE;
+      1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < VECTOR_SIZE; ++i) {
     vector[ids[i]] = T(1);
   }
-  end = grnxx::SteadyClock::now();
   double boundary_set_2nd_elapsed =
-      1000.0 * (end - start).count() / VECTOR_SIZE;
+      1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < VECTOR_SIZE; ++i) {
     total += vector[ids[i]];
   }
-  end = grnxx::SteadyClock::now();
   double boundary_get_elapsed =
-      1000.0 * (end - start).count() / VECTOR_SIZE;
+      1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
   const std::uint32_t block_id = vector.block_id();
   vector.close();
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   grnxx::db::Vector<T>::unlink(pool, block_id);
-  end = grnxx::SteadyClock::now();
-  double unlink_elapsed = 1000.0 * (end - start).count();
+  double unlink_elapsed = 1000.0 * stopwatch.elapsed().count();
 
   vector.create(pool, 0);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint64_t id = 0; id < VECTOR_SIZE; ++id) {
     vector[id] = T(0);
   }
-  end = grnxx::SteadyClock::now();
-  double default_elapsed = 1000.0 * (end - start).count() / VECTOR_SIZE;
+  double default_elapsed = 1000.0 * stopwatch.elapsed().count() / VECTOR_SIZE;
 
 
   GRNXX_NOTICE() << "elapsed [ns]: set = " << set_2nd_elapsed << " ("

  Modified: test/test_intrinsic.cpp (+19 -19)
===================================================================
--- test/test_intrinsic.cpp    2013-02-28 14:18:11 +0900 (2a71f58)
+++ test/test_intrinsic.cpp    2013-02-28 14:32:59 +0900 (23ccda2)
@@ -19,7 +19,7 @@
 
 #include "intrinsic.hpp"
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 void test_basics() {
   assert(grnxx::bit_scan_reverse(std::uint8_t(100)) == 6);
@@ -100,69 +100,69 @@ void test_times() {
 
   grnxx::Time start, end;
 
-  start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   std::uint64_t total = 0;
   for (std::uint32_t i = 1; i <= LOOP_COUNT; ++i) {
     total += grnxx::bit_scan_reverse(i);
   }
-  end = grnxx::SteadyClock::now();
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "bit_scan_reverse<32>: total = " << total
                  << ", elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   total = 0;
   for (std::uint64_t i = 1; i <= LOOP_COUNT; ++i) {
     total += grnxx::bit_scan_reverse(i << 20);
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "bit_scan_reverse<64>: total = " << total
                  << ", elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   volatile std::uint32_t count_32 = 0;
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     assert(grnxx::atomic_fetch_and_add(1, &count_32) == i);
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   assert(count_32 == LOOP_COUNT);
   GRNXX_NOTICE() << "atomic_fetch_and_add<32>: total = " << count_32
                  << ", elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   volatile std::uint64_t count_64 = 0;
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     assert(grnxx::atomic_fetch_and_add(1, &count_64) == i);
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   assert(count_64 == LOOP_COUNT);
   GRNXX_NOTICE() << "atomic_fetch_and_add<64>: total = " << count_64
                  << ", elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   const std::int32_t a_32 = 0, b_32 = 1;
   volatile std::int32_t value_32 = a_32;
   for (std::uint32_t i = 0; i < (LOOP_COUNT / 2); ++i) {
     assert(grnxx::atomic_compare_and_swap(a_32, b_32, &value_32));
     assert(grnxx::atomic_compare_and_swap(b_32, a_32, &value_32));
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "atomic_compare_and_swap<32>: elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   const std::int64_t a_64 = 0, b_64 = 1;
   volatile std::int64_t value_64 = a_64;
   for (std::uint32_t i = 0; i < (LOOP_COUNT / 2); ++i) {
     assert(grnxx::atomic_compare_and_swap(a_64, b_64, &value_64));
     assert(grnxx::atomic_compare_and_swap(b_64, a_64, &value_64));
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "atomic_compare_and_swap<64>: elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 }
 
 int main() {

  Modified: test/test_io_pool.cpp (+13 -13)
===================================================================
--- test/test_io_pool.cpp    2013-02-28 14:18:11 +0900 (ea01491)
+++ test/test_io_pool.cpp    2013-02-28 14:32:59 +0900 (cbb720e)
@@ -23,7 +23,7 @@
 
 #include "io/pool.hpp"
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 void test_constructor() {
   grnxx::io::Pool::unlink_if_exists("temp.grn");
@@ -362,56 +362,56 @@ void benchmark() {
   grnxx::io::Pool pool(grnxx::io::POOL_TEMPORARY, "temp.grn");
 
   // Measure the speed of create_block().
-  grnxx::Time start_time = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     block_infos[i] = pool.create_block(0);
   }
-  grnxx::Duration elapsed = grnxx::SteadyClock::now() - start_time;
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "create_block: elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 
   // Measure the speed of get_block_info().
-  start_time = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     pool.get_block_info(block_infos[i]->id());
   }
-  elapsed = grnxx::SteadyClock::now() - start_time;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "get_block_info: elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 
   // Measure the speed of get_block_address().
-  start_time = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     pool.get_block_address(*block_infos[i]);
   }
-  elapsed = grnxx::SteadyClock::now() - start_time;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "get_block_address_by_info (1st): elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 
   // Measure the speed of get_block_address() again.
-  start_time = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     pool.get_block_address(*block_infos[i]);
   }
-  elapsed = grnxx::SteadyClock::now() - start_time;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "get_block_address_by_info (2nd): elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 
   // Measure the speed of get_block_address() again and again.
-  start_time = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     pool.get_block_address(block_infos[i]->id());
   }
-  elapsed = grnxx::SteadyClock::now() - start_time;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "get_block_address_by_id: elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 
   // Measure the speed of free_block().
-  start_time = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < OPERATION_COUNT; ++i) {
     pool.free_block(block_infos[i]->id());
   }
-  elapsed = grnxx::SteadyClock::now() - start_time;
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "free_block: elapsed [ns] = "
                  << (1000.0 * elapsed.count() / OPERATION_COUNT);
 }

  Modified: test/test_mutex.cpp (+4 -5)
===================================================================
--- test/test_mutex.cpp    2013-02-28 14:18:11 +0900 (bff7291)
+++ test/test_mutex.cpp    2013-02-28 14:32:59 +0900 (43d0b1c)
@@ -20,7 +20,7 @@
 #include "lock.hpp"
 #include "logger.hpp"
 #include "mutex.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 int main() {
   grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
@@ -64,15 +64,14 @@ int main() {
 
   enum { LOOP_COUNT = 1 << 20 };
 
-  const grnxx::Time start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {
     grnxx::Lock lock(&mutex);
     assert(lock);
   }
-  const grnxx::Time end = grnxx::SteadyClock::now();
-
+  const grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::Lock: elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
   return 0;
 }

  Modified: test/test_recycler.cpp (+5 -7)
===================================================================
--- test/test_recycler.cpp    2013-02-28 14:18:11 +0900 (c1073ab)
+++ test/test_recycler.cpp    2013-02-28 14:32:59 +0900 (118c508)
@@ -19,7 +19,7 @@
 
 #include "logger.hpp"
 #include "recycler.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 void test() {
   const grnxx::Duration FROZEN_DURATION = grnxx::Duration::minutes(10);
@@ -52,22 +52,20 @@ void benchmark(grnxx::Duration frozen_duration) {
 
   double stamp_elapsed;
   {
-    const grnxx::Time start = grnxx::SteadyClock::now();
+    grnxx::Stopwatch stopwatch(true);
     for (int i = 0; i < STAMP_COUNT; ++i) {
       recycler.stamp();
     }
-    const grnxx::Time end = grnxx::SteadyClock::now();
-    stamp_elapsed = 1000.0 * (end - start).count() / STAMP_COUNT;
+    stamp_elapsed = 1000.0 * stopwatch.elapsed().count() / STAMP_COUNT;
   }
 
   double check_elapsed;
   {
-    const grnxx::Time start = grnxx::SteadyClock::now();
+    grnxx::Stopwatch stopwatch(true);
     for (int i = 0; i < CHECK_COUNT; ++i) {
       recycler.check(std::uint16_t(i));
     }
-    const grnxx::Time end = grnxx::SteadyClock::now();
-    check_elapsed = 1000.0 * (end - start).count() / CHECK_COUNT;
+    check_elapsed = 1000.0 * stopwatch.elapsed().count() / CHECK_COUNT;
   }
 
   GRNXX_NOTICE() << "frozen_duration = " << frozen_duration

  Modified: test/test_string.cpp (+7 -8)
===================================================================
--- test/test_string.cpp    2013-02-28 14:18:11 +0900 (651108f)
+++ test/test_string.cpp    2013-02-28 14:32:59 +0900 (496151b)
@@ -19,7 +19,7 @@
 
 #include "logger.hpp"
 #include "string.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 void test_constructors() {
   assert(!grnxx::String());
@@ -141,23 +141,22 @@ void benchmark() {
   grnxx::String str, str2;
   grnxx::Time start, end;
 
-  start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {
     str = grnxx::String("This is an apple.");
   }
-  end = grnxx::SteadyClock::now();
-
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "string creation: elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < LOOP_COUNT; ++i) {
     str2 = str;
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
 
   GRNXX_NOTICE() << "string copy: elapsed [ns] = "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 }
 
 int main() {

  Modified: test/test_string_format.cpp (+28 -28)
===================================================================
--- test/test_string_format.cpp    2013-02-28 14:18:11 +0900 (ea4c0b6)
+++ test/test_string_format.cpp    2013-02-28 14:32:59 +0900 (3b533c1)
@@ -21,7 +21,7 @@
 #include <sstream>
 
 #include "logger.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 #include "string_format.hpp"
 
 void test_align() {
@@ -114,90 +114,90 @@ void benchmark() {
   grnxx::Time start, end;
 
 
-  start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::snprintf(buf, sizeof(buf), "%d", __LINE__);
   }
-  end = grnxx::SteadyClock::now();
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::snprintf(int): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::snprintf(buf, sizeof(buf), "%04d", __LINE__);
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::snprintf(align_right): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::snprintf(buf, sizeof(buf), "%s:%d: %s: In %s(): %s",
                   __FILE__, __LINE__, "error", __func__, "failed");
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::snprintf(complex): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::stringstream stream;
     stream.rdbuf()->pubsetbuf(buf, sizeof(buf));
     stream << __LINE__;
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::ostream(int): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::stringstream stream;
     stream.rdbuf()->pubsetbuf(buf, sizeof(buf));
     stream << std::setw(4) << std::setfill('0') << __LINE__;
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::ostream(align_right): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     std::stringstream stream;
     stream.rdbuf()->pubsetbuf(buf, sizeof(buf));
     stream << __FILE__ << ':' << __LINE__ << ": " << "error" << ": In "
            << __func__ << "(): " << "failed";
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "std::ostream(complex): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     grnxx::StringBuilder(buf).builder() << __LINE__;
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::StringBuilder(int): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     grnxx::StringBuilder(buf).builder()
         << grnxx::StringFormat::align_right(__LINE__, 4, '0');
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::StringBuilder(align_right): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (std::uint32_t i = 0; i < LOOP_COUNT; ++i) {
     grnxx::StringBuilder(buf).builder()
         << __FILE__ << ':' << __LINE__ << ": "
         << "error" << ": In " << __func__ << "(): " << "failed";
   }
-  end = grnxx::SteadyClock::now();
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::StringBuilder(complex): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 }
 
 int main() {

  Modified: test/test_thread.cpp (+10 -13)
===================================================================
--- test/test_thread.cpp    2013-02-28 14:18:11 +0900 (5354fd3)
+++ test/test_thread.cpp    2013-02-28 14:32:59 +0900 (ef5d8c9)
@@ -19,7 +19,7 @@
 
 #include "logger.hpp"
 #include "thread.hpp"
-#include "steady_clock.hpp"
+#include "stopwatch.hpp"
 
 int main() {
   grnxx::Logger::set_flags(grnxx::LOGGER_WITH_ALL |
@@ -28,30 +28,27 @@ int main() {
 
   enum { LOOP_COUNT = 1000 };
 
-  grnxx::Time start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {
     grnxx::Thread::switch_to_others();
   }
-  grnxx::Time end = grnxx::SteadyClock::now();
-
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "switch_to_others(): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < LOOP_COUNT; ++i) {
     grnxx::Thread::sleep(grnxx::Duration(0));
   }
-  end = grnxx::SteadyClock::now();
-
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "sleep(0): elapsed [ns]: "
-                 << (1000.0 * (end - start).count() / LOOP_COUNT);
+                 << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   grnxx::Thread::sleep(grnxx::Duration::milliseconds(10));
-  end = grnxx::SteadyClock::now();
-
+  elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "sleep(10ms): elapsed [ns] = "
-                 << (1000.0 * (end - start).count());
+                 << (1000.0 * elapsed.count());
 
   return 0;
 }

  Modified: test/test_time.cpp (+6 -10)
===================================================================
--- test/test_time.cpp    2013-02-28 14:18:11 +0900 (cfc765e)
+++ test/test_time.cpp    2013-02-28 14:32:59 +0900 (0aaa151)
@@ -19,6 +19,7 @@
 
 #include "logger.hpp"
 #include "steady_clock.hpp"
+#include "stopwatch.hpp"
 #include "system_clock.hpp"
 
 int main() {
@@ -39,25 +40,20 @@ int main() {
 
   enum { LOOP_COUNT = 1 << 16 };
 
-  grnxx::Time start = grnxx::SteadyClock::now();
+  grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {
     grnxx::SystemClock::now();
   }
-  grnxx::Time end = grnxx::SteadyClock::now();
-
-  grnxx::Duration elapsed = end - start;
+  grnxx::Duration elapsed = stopwatch.elapsed();
   GRNXX_NOTICE() << "grnxx::SystemClock::now: average elapsed [ns] = "
                  << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  start = grnxx::SteadyClock::now();
+  stopwatch.reset();
   for (int i = 0; i < LOOP_COUNT; ++i) {
     grnxx::SteadyClock::now();
   }
-  end = grnxx::SteadyClock::now();
-
-  elapsed = end - start;
-  GRNXX_NOTICE() << "grnxx::SteadyClock::now"
-                 << ": average elapsed [ns] = "
+  elapsed = stopwatch.elapsed();
+  GRNXX_NOTICE() << "grnxx::SteadyClock::now: average elapsed [ns] = "
                  << (1000.0 * elapsed.count() / LOOP_COUNT);
 
   return 0;
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index