![]() |
![]() |
|
![]() |
|||||||||||||
![]() |
||||||||||||||||
|
Easy Performance Analysis
This solution presents a way of using cyTimer
code release to easily analyze the performance of your code
(Note that cyTimer requires Windows operating system).
Here, we will use a new class,
You will first need to download timerlist.h,
which includes the implementation of 1. Editing timerlist.h
Let's assume that your code has two major parts and you would like to know
their performances. The first part has, say, 3 sub-parts and the second part
has 2 sub-parts. In this case, we can use 7 timers, 2 of which
will measure each part as a whole, and the other 5 (3+2) will measure each
individual sub-part.
In the beginning of timerlist.h file
// ID of each timer and the number of timers
enum TimerType
{
TT_PART1=0,
TT_PART1_SUB1,
TT_PART1_SUB2,
TT_PART1_SUB3,
TT_PART2,
TT_PART2_SUB1,
TT_PART2_SUB2,
TIMER_TYPE_COUNT // this keeps the number of timers (DO NOT REMOVE)
};
// The name string of each timer
static char TimerTypeNames[][255] = {
"Part 1 ",
" Part 1 algorithm 1 ",
" Part 1 algorithm 2 ",
" Part 1 algorithm 3 ",
"Part 2 ",
" Part 2 algorithm 1 ",
" Part 2 algorithm 2 ",
};
All you need to do is to edit 2. Using timerlist.h
We first need to include the following line in one of the source files,
which defines a global TimerList TIMER;
To measure the time, we access each timer separately and use TIMER[ TT_PART1 ].Start(); // First part starts TIMER[ TT_PART1_SUB1 ].Start(); // The first sub-part in part 1 code will be here TIMER[ TT_PART1_SUB1 ].Stop(); TIMER[ TT_PART1_SUB2 ].Start(); // The second sub-part in part 1 code will be here TIMER[ TT_PART1_SUB2 ].Stop(); TIMER[ TT_PART1_SUB3 ].Start(); // The final sub-part in part 1 code will be here TIMER[ TT_PART1_SUB3 ].Stop(); // Some more stuff in part 1 TIMER[ TT_PART1 ].Stop();
The above code can be executed as many times as we like. TIMER.PrintResults( TT_PART1, TT_PART2 );
This will print the results of part 1 to the | ||||||||||||||||
![]() |
![]() |
|||||||||||||||