Skip to content

Instantly share code, notes, and snippets.

@marksands
Created April 15, 2010 04:34
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 marksands/366681 to your computer and use it in GitHub Desktop.
Save marksands/366681 to your computer and use it in GitHub Desktop.
#include <ctime>
#include <iomanip>
#include <iostream>
using std::setw;
using std::cout;
using std::endl;
class Timer {
private:
clock_t start, finish;
public:
Timer() { start = clock(); }
~Timer() { finish = clock();
cout << setw(5) << " "
<< "Total time: "
<< ((double)(finish - start)/CLOCKS_PER_SEC)
<< endl; }
};
int main() {
Timer t;
size_t i;
for ( i = 0; i < 100000000; i++ );
return 0;
}
/*
output:
Total time: 0.358133
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment