libfoedus-core
FOEDUS Core Library
stop_watch.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_DEBUGGING_STOP_WATCH_HPP_
19 #define FOEDUS_DEBUGGING_STOP_WATCH_HPP_
20 #include <stdint.h>
21 namespace foedus {
22 namespace debugging {
30 class StopWatch {
31  public:
32  StopWatch() : started_(0), stopped_(0) { start(); }
33 
35  void start();
36 
38  uint64_t stop();
39 
40  uint64_t peek_elapsed_ns() const;
41 
42  uint64_t elapsed_ns() const {
43  return stopped_ - started_;
44  }
45  double elapsed_us() const {
46  return static_cast<double>(stopped_ - started_) / 1000.0;
47  }
48  double elapsed_ms() const {
49  return static_cast<double>(stopped_ - started_) / 1000000.0;
50  }
51  double elapsed_sec() const {
52  return static_cast<double>(stopped_ - started_) / 1000000000.0;
53  }
54 
55  private:
56  uint64_t started_;
57  uint64_t stopped_;
58 };
59 
60 } // namespace debugging
61 } // namespace foedus
62 
63 #endif // FOEDUS_DEBUGGING_STOP_WATCH_HPP_
void start()
Take current time tick.
Definition: stop_watch.cpp:30
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
double elapsed_ms() const
Definition: stop_watch.hpp:48
uint64_t stop()
Take another current time tick.
Definition: stop_watch.cpp:35
double elapsed_us() const
Definition: stop_watch.hpp:45
double elapsed_sec() const
Definition: stop_watch.hpp:51
A high-resolution stop watch.
Definition: stop_watch.hpp:30
uint64_t peek_elapsed_ns() const
Definition: stop_watch.cpp:39
uint64_t elapsed_ns() const
Definition: stop_watch.hpp:42