Real Time Systems Design And Analysis

Chapter 7.2.1.3 - Using the System Clock

7.2.1.3   Using the System Clock   Sections of code can be timed by reading
the system clock before and after the execution of the code. The time difference
can then be measured to determine the actual time of execution. If this
technique is used, it is necessary to calculate the actual time spent in the open
loop and subtract it from the total. Of course, if the code normally takes only
a few microseconds, it is better to execute the code under examination several
thousand times. This will help to remove any inaccuracy introduced by the granularity
of the clock. For example, the following C code can be rewritten in a
suitable language to time a single high-level language instruction or series of
instructions. The number of iterations needed can be varied depending on how
short the code to be timed is. The shorter the code, the more iterations should
be used. current_clock_time( ) is a system function that returns the current
time. function_to_be_timed( ) is where the actual code to be timed is placed.

Accuracy due to the clock resolution should be taken into account. For example,
if 2000 iterations of the function take 1.1 seconds with a clock granularity of
18.2 microseconds, the measurement is accurate to

 

Clearly, running more iterations can increase the accuracy of the measurement.

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: PCMCIA Memory Cards
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.