Created
October 3, 2019 02:45
-
-
Save gghatano/c964d1a98b9cdbbcbbf4334f33561586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"ProcessingTime.hpp" | |
int main(){ | |
{ | |
ProcessingTime pt("Test"); | |
int sum = 0; | |
int N = 1000000; | |
for (int i = 0; i < N; i ++){ | |
sum += i; | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<chrono> | |
class ProcessingTime{ | |
public: | |
ProcessingTime(const std::string& name = "Process", bool start = true) : | |
m_name(name), | |
m_isActive(start) | |
{ | |
if (start) | |
{ | |
this->restart(); | |
} | |
} | |
~ProcessingTime() | |
{ | |
this->stop(); | |
} | |
///<summary> | |
///計測のリスタート | |
///</summary> | |
void restart()& | |
{ | |
m_start = std::chrono::system_clock::now(); | |
m_isActive = true; | |
} | |
///<summary> | |
///計測を終了し出力 | |
///</summary> | |
void stop()& | |
{ | |
if (!m_isActive) | |
return; | |
const auto end = std::chrono::system_clock::now(); | |
const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds >(end - m_start).count(); | |
std::cout << elapsed <<"ms"<< std::endl; | |
m_isActive = false; | |
} | |
private: | |
std::string m_name; | |
std::chrono::system_clock::time_point m_start; | |
bool m_isActive; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment