1#include "BenchTimer.h" 2#if defined(SK_BUILD_FOR_WIN32) 3 #include "BenchSysTimer_windows.h" 4#elif defined(SK_BUILD_FOR_MAC) 5 #include "BenchSysTimer_mach.h" 6#elif defined(SK_BUILD_FOR_UNIX) 7 #include "BenchSysTimer_posix.h" 8#else 9 #include "BenchSysTimer_c.h" 10#endif 11 12#if defined(SK_MESA) || \ 13 defined(SK_BUILD_FOR_WIN32) || \ 14 defined(SK_BUILD_FOR_MAC) || \ 15 defined(SK_BUILD_FOR_UNIX) 16 #include "BenchGpuTimer_gl.h" 17 18#else 19 #include "BenchGpuTimer_none.h" 20#endif 21 22BenchTimer::BenchTimer() 23 : fCpu(-1.0) 24 , fWall(-1.0) 25 , fGpu(-1.0) 26{ 27 this->fSysTimer = new BenchSysTimer(); 28 this->fGpuTimer = new BenchGpuTimer(); 29} 30 31BenchTimer::~BenchTimer() { 32 delete this->fSysTimer; 33 delete this->fGpuTimer; 34} 35 36void BenchTimer::start() { 37 this->fSysTimer->startWall(); 38 this->fGpuTimer->startGpu(); 39 this->fSysTimer->startCpu(); 40} 41 42void BenchTimer::end() { 43 this->fCpu = this->fSysTimer->endCpu(); 44 //It is important to stop the cpu clocks first, 45 //as the following will cpu wait for the gpu to finish. 46 this->fGpu = this->fGpuTimer->endGpu(); 47 this->fWall = this->fSysTimer->endWall(); 48} 49