[pixkit timer] Tool for evaluating execution time - yunfuliu/pixkit GitHub Wiki
Timer
Tool for evaluating execution time.
C++: class Timer{};
Member functions:
- void Start() - Start to count execution time.
- void Stop() - Stop to count execution time.
- void Reset() - Reset all the settings.
- bool Report() - Report current status.
- bool StopAndReport() - Stop to count execution time and report current status.
- float TimeInSeconds() - Return cumulative execution time.
- float AvgTime() - Return average execution time.
Example 1:
pixkit::Timer tmr1("c1");
for(int i=0;i<5;i++){
tmr1.Start();
func();
tmr1.StopAndReport();
}
/////////////////////////
// output
[c1] CumuTime: 0.0349389s, #run: 1, AvgTime: 0.0349389s
[c1] CumuTime: 0.0566038s, #run: 2, AvgTime: 0.0283019s
[c1] CumuTime: 0.0779796s, #run: 3, AvgTime: 0.0259932s
[c1] CumuTime: 0.0995171s, #run: 4, AvgTime: 0.0248793s
[c1] CumuTime: 0.121104s, #run: 5, AvgTime: 0.0242207s
Example 2:
for(int i=0;i<5;i++){
static pixkit::Timer tmr2("c2");
tmr2.Start();
func();
tmr2.Stop();
tmr2.Report();
}
/////////////////////////
// output
[c2] CumuTime: 0.0213429s, #run: 1, AvgTime: 0.0213429s
[c2] CumuTime: 0.0428791s, #run: 2, AvgTime: 0.0214395s
[c2] CumuTime: 0.0644379s, #run: 3, AvgTime: 0.0214793s
[c2] CumuTime: 0.0858289s, #run: 4, AvgTime: 0.0214572s
[c2] CumuTime: 0.107342s, #run: 5, AvgTime: 0.0214683s
Example 3:
pixkit::Timer tmr3("c3");
tmr3.Start();
func1();
tmr3.StopAndReport();
tmr3.Reset();
tmr3.Start();
func2();
tmr3.StopAndReport();
/////////////////////////
// output
[c3] CumuTime: 0.021593s, #run: 1, AvgTime: 0.021593s
[c3] CumuTime: 0.0429455s, #run: 1, AvgTime: 0.0429455s