[Groonga-commit] groonga/grnxx [master] Remove grnxx::SteadyClock.

Back to archive index

susumu.yata null+****@clear*****
Fri Mar 1 18:26:05 JST 2013


susumu.yata	2013-03-01 18:26:05 +0900 (Fri, 01 Mar 2013)

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

  Log:
    Remove grnxx::SteadyClock.

  Removed files:
    lib/steady_clock.cpp
    lib/steady_clock.hpp
  Modified files:
    lib/Makefile.am
    lib/stopwatch.cpp
    lib/stopwatch.hpp
    test/test_intrinsic.cpp
    test/test_string.cpp
    test/test_string_format.cpp
    test/test_time.cpp

  Modified: lib/Makefile.am (+0 -2)
===================================================================
--- lib/Makefile.am    2013-03-01 18:07:43 +0900 (9ef39b8)
+++ lib/Makefile.am    2013-03-01 18:26:05 +0900 (d89cb0a)
@@ -23,7 +23,6 @@ libgrnxx_la_SOURCES =		\
 	os.cpp			\
 	recycler.cpp		\
 	slice.cpp		\
-	steady_clock.cpp	\
 	stopwatch.cpp		\
 	string.cpp		\
 	string_builder.cpp	\
@@ -51,7 +50,6 @@ libgrnxx_include_HEADERS =	\
 	os.hpp			\
 	recycler.hpp		\
 	slice.hpp		\
-	steady_clock.hpp	\
 	string.hpp		\
 	string_builder.hpp	\
 	string_format.hpp	\

  Deleted: lib/steady_clock.cpp (+0 -29) 100644
===================================================================
--- lib/steady_clock.cpp    2013-03-01 18:07:43 +0900 (935e500)
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-  Copyright (C) 2013  Brazil, Inc.
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#include "steady_clock.hpp"
-
-#include <chrono>
-
-namespace grnxx {
-
-Time SteadyClock::now() {
-  return Time(std::chrono::duration_cast<std::chrono::microseconds>(
-              std::chrono::steady_clock::now().time_since_epoch()).count());
-}
-
-}  // namespace grnxx

  Deleted: lib/steady_clock.hpp (+0 -33) 100644
===================================================================
--- lib/steady_clock.hpp    2013-03-01 18:07:43 +0900 (60cf1b2)
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-  Copyright (C) 2013  Brazil, Inc.
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#ifndef GRNXX_STEADY_CLOCK_HPP
-#define GRNXX_STEADY_CLOCK_HPP
-
-#include "basic.hpp"
-#include "time.hpp"
-
-namespace grnxx {
-
-class SteadyClock {
- public:
-  static Time now();
-};
-
-}  // namespace grnxx
-
-#endif  // GRNXX_STEADY_CLOCK_HPP

  Modified: lib/stopwatch.cpp (+16 -11)
===================================================================
--- lib/stopwatch.cpp    2013-03-01 18:07:43 +0900 (e66ad57)
+++ lib/stopwatch.cpp    2013-03-01 18:26:05 +0900 (d636f2a)
@@ -17,43 +17,48 @@
 */
 #include "stopwatch.hpp"
 
-#include "steady_clock.hpp"
+#include <chrono>
+//#include "steady_clock.hpp"
 
 namespace grnxx {
+namespace {
+
+int64_t now() {
+  return std::chrono::duration_cast<std::chrono::microseconds>(
+      std::chrono::steady_clock::now().time_since_epoch()).count();
+}
+
+}  // namespace
 
 Stopwatch::Stopwatch(bool is_running)
   : elapsed_(0),
-    start_time_(),
-    is_running_(is_running) {
-  if (is_running) {
-    start_time_ = SteadyClock::now();
-  }
-}
+    start_count_(is_running ? now() : 0),
+    is_running_(is_running) {}
 
 void Stopwatch::start() {
   if (!is_running_) {
-    start_time_ = SteadyClock::now();
+    start_count_ = now();
     is_running_ = true;
   }
 }
 
 void Stopwatch::stop() {
   if (is_running_) {
-    elapsed_ += SteadyClock::now() - start_time_;
+    elapsed_ += Duration(now() - start_count_);
     is_running_ = false;
   }
 }
 
 void Stopwatch::reset() {
   if (is_running_) {
-    start_time_ = SteadyClock::now();
+    start_count_ = now();
   }
   elapsed_ = Duration(0);
 }
 
 Duration Stopwatch::elapsed() const {
   if (is_running_) {
-    return elapsed_ + (SteadyClock::now() - start_time_);
+    return elapsed_ + Duration(now() - start_count_);
   } else {
     return elapsed_;
   }

  Modified: lib/stopwatch.hpp (+2 -2)
===================================================================
--- lib/stopwatch.hpp    2013-03-01 18:07:43 +0900 (a97d2b3)
+++ lib/stopwatch.hpp    2013-03-01 18:26:05 +0900 (2eb308a)
@@ -19,7 +19,7 @@
 #define GRNXX_STOPWATCH_HPP
 
 #include "basic.hpp"
-#include "time.hpp"
+#include "duration.hpp"
 
 namespace grnxx {
 
@@ -51,7 +51,7 @@ class Stopwatch {
 
  private:
   Duration elapsed_;
-  Time start_time_;
+  int64_t start_count_;
   bool is_running_;
 };
 

  Modified: test/test_intrinsic.cpp (+0 -2)
===================================================================
--- test/test_intrinsic.cpp    2013-03-01 18:07:43 +0900 (23ccda2)
+++ test/test_intrinsic.cpp    2013-03-01 18:26:05 +0900 (eb14319)
@@ -98,8 +98,6 @@ void test_basics() {
 void test_times() {
   enum { LOOP_COUNT = 1 << 20 };
 
-  grnxx::Time start, end;
-
   grnxx::Stopwatch stopwatch(true);
   std::uint64_t total = 0;
   for (std::uint32_t i = 1; i <= LOOP_COUNT; ++i) {

  Modified: test/test_string.cpp (+0 -1)
===================================================================
--- test/test_string.cpp    2013-03-01 18:07:43 +0900 (496151b)
+++ test/test_string.cpp    2013-03-01 18:26:05 +0900 (34b1084)
@@ -139,7 +139,6 @@ void benchmark() {
   const int LOOP_COUNT = 1 << 16;
 
   grnxx::String str, str2;
-  grnxx::Time start, end;
 
   grnxx::Stopwatch stopwatch(true);
   for (int i = 0; i < LOOP_COUNT; ++i) {

  Modified: test/test_string_format.cpp (+0 -1)
===================================================================
--- test/test_string_format.cpp    2013-03-01 18:07:43 +0900 (3b533c1)
+++ test/test_string_format.cpp    2013-03-01 18:26:05 +0900 (380a2dc)
@@ -111,7 +111,6 @@ void benchmark() {
   static const std::uint32_t LOOP_COUNT = 1 << 16;
 
   char buf[1024] = "";
-  grnxx::Time start, end;
 
 
   grnxx::Stopwatch stopwatch(true);

  Modified: test/test_time.cpp (+0 -14)
===================================================================
--- test/test_time.cpp    2013-03-01 18:07:43 +0900 (f6358d0)
+++ test/test_time.cpp    2013-03-01 18:26:05 +0900 (5593767)
@@ -18,7 +18,6 @@
 #include <cassert>
 
 #include "logger.hpp"
-#include "steady_clock.hpp"
 #include "stopwatch.hpp"
 #include "system_clock.hpp"
 
@@ -37,11 +36,6 @@ int main() {
   GRNXX_NOTICE() << "grnxx::SystemClock::now().local_time(): "
                  << time.local_time();
 
-  time = grnxx::SteadyClock::now();
-  GRNXX_NOTICE() << "grnxx::SteadyClock::now(): " << time;
-  GRNXX_NOTICE() << "grnxx::SteadyClock::now().local_time(): "
-                 << time.local_time();
-
   enum { LOOP_COUNT = 1 << 16 };
 
   grnxx::Stopwatch stopwatch(true);
@@ -52,13 +46,5 @@ int main() {
   GRNXX_NOTICE() << "grnxx::SystemClock::now: average elapsed [ns] = "
                  << (1000.0 * elapsed.count() / LOOP_COUNT);
 
-  stopwatch.reset();
-  for (int i = 0; i < LOOP_COUNT; ++i) {
-    grnxx::SteadyClock::now();
-  }
-  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