#ifndef _Timer #define _Timer /* Utility for timing in c++ */ class Timer { public: int PrintLevel; clock_t StartTime; clock_t StopTime; double CpuTimeUsed; string Name; /* Constructor 1 */ Timer() { PrintLevel = 1; CpuTimeUsed = 0.0; Name = "NoName"; } /* Constructor 2 */ Timer(int PrintLevel) : PrintLevel(PrintLevel) { CpuTimeUsed = 0.0; Name = "NoName"; } /* Set the Start Time */ void Start() { if(PrintLevel) cout << "Start Timer " << Name << "\n"; StartTime = clock(); } void Pause() { if(PrintLevel) cout << "Pause Timer " << Name << "\n"; StopTime = clock(); CpuTimeUsed += ((double)(StopTime - StartTime)) / CLOCKS_PER_SEC; } /* Set the End Time */ double Stop() { StopTime = clock(); CpuTimeUsed += ((double)(StopTime - StartTime)) / CLOCKS_PER_SEC; if(PrintLevel) cout << "End Timer " << Name << ". CPU Time Used: " << CpuTimeUsed << "s (" << CpuTimeUsed/60.0 << "m)"; double Temp = CpuTimeUsed; CpuTimeUsed = 0.0; return Temp; } }; #endif