PeriDyno 1.0.0
Loading...
Searching...
No Matches
Timer.cpp
Go to the documentation of this file.
1#include "Timer.h"
2
3namespace dyno
4{
6 {
7#if (defined _WIN32)
8 QueryPerformanceFrequency(&timer_frequency_);
9#endif
10 start();
11 }
12
14 {
15 }
16
18 {
19#if (defined __unix__) || (defined __APPLE__)
20 timeval tv;
21 gettimeofday(&tv, 0);
22 start_sec_ = tv.tv_sec;
23 start_micro_sec_ = tv.tv_usec;
24#elif (defined _WIN32)
25 QueryPerformanceCounter(&start_count_);
26#endif
27 }
28
30 {
31#if (defined __unix__) || (defined __APPLE__)
32 timeval tv;
33 gettimeofday(&tv, 0);
34 stop_sec_ = tv.tv_sec;
35 stop_micro_sec_ = tv.tv_usec;
36#elif (defined _WIN32)
37 QueryPerformanceCounter(&stop_count_);
38#endif
39 }
40
42 {
43#if (defined __unix__) || (defined __APPLE__)
44 double elapsed_time = 1.0 * (stop_sec_ - start_sec_) + 1.0e-6 * (stop_micro_sec_ - start_micro_sec_);
45 return elapsed_time;
46#elif (defined _WIN32)
47 double elapsed_time = static_cast<double>(stop_count_.QuadPart - start_count_.QuadPart) / static_cast<double>(timer_frequency_.QuadPart);
48 return 1000.0 * elapsed_time;
49#endif
50 }
51
52 void CTimer::outputString(char* str)
53 {
54 std::cout << str << ": " << getElapsedTime() << "ms" << std::endl;
55 }
56
57#ifdef CUDA_BACKEND
58 GTimer::GTimer()
59 {
60 milliseconds = 0.0f;
61 cudaEventCreate(&m_start);
62 cudaEventCreate(&m_stop);
63 }
64
65 GTimer::~GTimer()
66 {
67 }
68
69 void GTimer::start()
70 {
71 cudaEventRecord(m_start, 0);
72 }
73
74 void GTimer::stop()
75 {
76 cudaEventRecord(m_stop, 0);
77 cudaEventSynchronize(m_stop);
78 cudaEventElapsedTime(&milliseconds, m_start, m_stop);
79 }
80
81 float GTimer::getElapsedTime()
82 {
83 return milliseconds;
84 }
85
86 void GTimer::outputString(const char* str)
87 {
88 std::cout << str << ": " << getElapsedTime() << "ms" << std::endl;
89 }
90#endif
91} // end of namespace dyno
double getElapsedTime()
return the elapsed time in (ms)
Definition Timer.cpp:41
void start()
Definition Timer.cpp:17
void stop()
Definition Timer.cpp:29
void outputString(char *str)
Definition Timer.cpp:52
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25