00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "timer.h"
00028
00029
00030 Timer::Timer()
00031 {
00032 #if defined( PBRT_IS_WINDOWS )
00033
00034 QueryPerformanceFrequency( &performance_frequency );
00035 one_over_frequency = 1.0/((double)performance_frequency.QuadPart);
00036 #endif
00037 time0 = elapsed = 0;
00038 running = 0;
00039 }
00040
00041
00042
00043
00044 double Timer::GetTime()
00045 {
00046 #if defined( PBRT_IS_WINDOWS )
00047
00048 QueryPerformanceCounter( &performance_counter );
00049 return (double) performance_counter.QuadPart * one_over_frequency;
00050 #else
00051
00052 gettimeofday( &timeofday, NULL );
00053 return timeofday.tv_sec + timeofday.tv_usec / 1000000.0;
00054 #endif
00055 }
00056
00057
00058
00059 void Timer::Start()
00060 {
00061 Assert( !running );
00062 running = 1;
00063 time0 = GetTime();
00064 }
00065
00066
00067
00068 void Timer::Stop()
00069 {
00070 Assert( running );
00071 running = 0;
00072
00073 elapsed += GetTime() - time0;
00074 }
00075
00076
00077
00078 void Timer::Reset()
00079 {
00080 running = 0;
00081 elapsed = 0;
00082 }
00083
00084
00085
00086 double Timer::Time()
00087 {
00088 if (running) {
00089 Stop();
00090 Start();
00091 }
00092 return elapsed;
00093 }
00094
00095