Coverage Report

Created: 2024-08-02 07:04

/src/assimp/contrib/Open3DGC/o3dgcTimer.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
21
*/
22
23
#pragma once
24
#ifndef O3DGC_TIMER_H
25
#define O3DGC_TIMER_H
26
27
#include "o3dgcCommon.h"
28
29
#ifdef _WIN32
30
/* Thank you, Microsoft, for file WinDef.h with min/max redefinition. */
31
#ifndef NOMINMAX
32
#define NOMINMAX
33
#endif
34
#include <windows.h>
35
#elif __APPLE__
36
#include <mach/clock.h>
37
#include <mach/mach.h>
38
#else
39
#include <time.h>
40
#include <sys/time.h>
41
#endif
42
43
44
45
namespace o3dgc
46
{
47
#ifdef _WIN32
48
    class Timer
49
    {
50
    public: 
51
        Timer(void)
52
        {
53
            m_start.QuadPart = 0;
54
            m_stop.QuadPart  = 0;
55
            QueryPerformanceFrequency( &m_freq ) ;
56
        };
57
        ~Timer(void){};
58
        void Tic() 
59
        {
60
            QueryPerformanceCounter(&m_start) ;
61
        }
62
        void Toc() 
63
        {
64
            QueryPerformanceCounter(&m_stop);
65
        }
66
        double GetElapsedTime() // in ms
67
        {
68
            LARGE_INTEGER delta;
69
            delta.QuadPart = m_stop.QuadPart - m_start.QuadPart;
70
            return (1000.0 * delta.QuadPart) / (double)m_freq.QuadPart;
71
        }
72
    private:
73
        LARGE_INTEGER m_start;
74
        LARGE_INTEGER m_stop;
75
        LARGE_INTEGER m_freq;
76
77
    };
78
#elif __APPLE__
79
    class Timer
80
    {
81
    public: 
82
        Timer(void)
83
        {
84
            memset(this, 0, sizeof(Timer));
85
            host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, & m_cclock);
86
        };
87
        ~Timer(void)
88
        {
89
            mach_port_deallocate(mach_task_self(),  m_cclock);
90
        };
91
        void Tic() 
92
        {
93
            clock_get_time( m_cclock, &m_start);
94
        }
95
        void Toc() 
96
        {
97
            clock_get_time( m_cclock, &m_stop);
98
        }
99
        double GetElapsedTime() // in ms
100
        {
101
            return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
102
        }
103
    private:
104
        clock_serv_t    m_cclock;
105
        mach_timespec_t m_start;
106
        mach_timespec_t m_stop;
107
    };
108
#else
109
    class Timer
110
    {
111
    public: 
112
        Timer(void)
113
0
        {
114
0
            memset(this, 0, sizeof(Timer));
115
0
        };
116
0
        ~Timer(void){};
117
        void Tic() 
118
0
        {
119
0
            clock_gettime(CLOCK_REALTIME, &m_start);
120
0
        }
121
        void Toc() 
122
0
        {
123
0
            clock_gettime(CLOCK_REALTIME, &m_stop);
124
0
        }
125
        double GetElapsedTime() // in ms
126
0
        {
127
0
            return 1000.0 * (m_stop.tv_sec - m_start.tv_sec + (1.0E-9) * (m_stop.tv_nsec - m_start.tv_nsec));
128
0
        }
129
    private:
130
         struct timespec m_start;
131
         struct timespec m_stop;
132
    };
133
#endif
134
135
}
136
#endif // O3DGC_TIMER_H