Skip to content

Instantly share code, notes, and snippets.

@disktnk
Last active December 13, 2015 23:39
Show Gist options
  • Save disktnk/4993393 to your computer and use it in GitHub Desktop.
Save disktnk/4993393 to your computer and use it in GitHub Desktop.
C++ (windows) でのミリ秒計測ログ埋め込み→クラス化、スレッドアンセーフ
#include<iostream>
#include<windows.h> // and link to "winmm.lib"
// code
DWORD startTime, endTime;
startTime = timeGetTime();
// ...
// elaplse target
// ...
endTime1 = timeGetTime();
std::cout << "elaplse time is..." << endTime - startTime << std::endl;
#include "PerformanceLog.h"
#include <iostream>
namespace foo{
PerformanceLog::PerformanceLog(std::string place) : place_(place)
{
startTime_ = timeGetTime();
}
PerformanceLog::~PerformanceLog(void)
{
endTime_ = timeGetTime();
std::cout << "[" << place_ << "]" << endTime_ - startTime_ << std::endl;
}
} // end of namespace
#include <string>
#include <windows.h>
namespace foo {
class PerformanceLog
{
public:
PerformanceLog(std::string place);
~PerformanceLog(void);
private:
DWORD startTime_;
DWORD endTime_;
std::string place_;
};
} // end of namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment