Skip to content

Instantly share code, notes, and snippets.

@hunandy14
Created January 12, 2018 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunandy14/d9034e595ce53f3112bbfde16398fe10 to your computer and use it in GitHub Desktop.
Save hunandy14/d9034e595ce53f3112bbfde16398fe10 to your computer and use it in GitHub Desktop.
計時器
/*****************************************************************
Name : Timer.hpp
Date : 2017/12/19
By : CharlotteHonG
Final: 2017/12/19
*****************************************************************/
#pragma once
#include <iostream>
#include <string>
#include <ctime>
class Timer {
public:
Timer(std::string name=""): name(name){
startTime = clock();
}
operator double() {
return time;
}
public:
void start() {
startTime = clock();
flag=0;
}
void end() {
finalTime = clock();
time = (double)(finalTime - startTime)/CLOCKS_PER_SEC;
}
void print(std::string name="") {
if (flag==0) {
flag = 1;
end();
}
if(name=="") {
name=this->name;
}
if(priSta) {
std::cout << "#" << name << ", " << " time = " << time << "s" << std::endl;
}
}
private:
std::string name;
clock_t startTime;
clock_t finalTime;
double time;
bool flag = 0;
public:
bool priSta = 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment