xingzilong
2017-08-18 9e5babf9db52e64bdae60137be7696e56241fca6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*********************************************************** 
* Date: 2016-06-30 
* Author: 牟韵 
* Email: mouyun1115@163.com 
* Module: 计时器 
* Brief: 
* Note: 
* CodePage: Pure UTF-8 
************************************************************/ 
#ifndef    __MY_TIMER_HPP_BY_MOUYUN_2014_09_28__
#define    __MY_TIMER_HPP_BY_MOUYUN_2014_09_28__
 
#include <chrono>
 
namespace my_module_space
{
    class Timer
    {
    public:
        Timer() : m_begin(std::chrono::high_resolution_clock::now()) {}
        ~Timer() {}
 
    private:
        Timer(const Timer&) = delete;
        Timer(Timer&&) = delete;
        Timer operator=(const Timer&) = delete;
 
    public:
        void reset()
        {
            m_begin = std::chrono::high_resolution_clock::now();
        }
 
        double tell_s() const
        {
            return std::chrono::duration_cast<std::chrono::duration<double> >(std::chrono::high_resolution_clock::now() - m_begin).count();
        }
 
        long long tell_ms() const
        {
            return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_begin).count();
        }
 
        long long tell_us() const
        {
            return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - m_begin).count();
        }
 
        long long tell_ns() const
        {
            return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - m_begin).count();
        }
 
    private:
        std::chrono::time_point<std::chrono::high_resolution_clock> m_begin;
    };
}
 
#endif