May 2002
Beginner
320 pages
6h 18m
English
You should always time your code to find out which parts of it are slow. This is an excellent application for test harnesses.
The Standard C library provides a time function for you to use. Unfortunately, it only measures time in one-second increments, so you will have to run many tests to get a time you can measure. For instance:
#include <time.h>
time_t Start;
time_t End;
time(&Start);
for (int Index = 0; Index < 100000; Index++)
{
int Value = Accumulator.Value();
} ;
time(&end);
double TimeRequired = difftime(Start,End);
Keep in mind that some operations cannot be easily or reliably performed in a loop of this sort. For instance:
#include <time.h> time_t Start; time_t End; time(&Start); for (int Index = 0; Index < 100000; ...
Read now
Unlock full access