This program simple loops through a simple process until 12 seconds
have gone by, according to the system. (There are a few minor errors;
for instance, clk_tck should be CLK_TCK, and the last value
clocks_per_sec is not defined anywhere, but should be a given value
used for comparison.) But basically, if it were compiling properly, it
should loop until the inner loop takes 12 seconds to complete,
displaying:
i k t1 t2 t time
and then the respective values for each iteration in the outer loop:
i: iteration, or number of times the loop has been executed.
k: slowly increases. x starts off as 1 and becomes 1.2 * its previous
value every iteration. k is the translation of that number by
truncating all places after the decimal point, i.e. 1.95 becomes 1,
but 2.34 becomes 2.
t1: the time, in ticks, since the program started operation, before
the second subloop (right under t1's assignment, "for(j=1;j<=k;j++);")
is executed; this loop should grow quickly, but running optimized will
probably not increase the delay significantly between rounds.
t2: the time after the loop, in ticks.
t: the difference between t1 and t2.
When the inner loop takes 12 or greater seconds to execute, the
program considers this a large enough value to obtain accurate data
from. Then it should display CLK_TCK, the system value for how many
clock ticks or operations there SHOULD be per second, and a formula
must be put in place of "clocks_per_sec" to calculate the following:
how many instructions the inner operation takes, times its current
number of loops (k), divided by number of seconds that have elapsed.
Note that this will not work on newer computers for at least a few
reasons: they're too fast, and k needs to be longer than a "long"
integer to work.
clock ticks cannot be obtained on many newer systems via CLK_TCK
(system returns 0).
And, some processors "pipeline" instructions, excecuting multiple
commands in a single clocktick, or optimize looped commands that they
can "forsee" by looking ahead at the code.
Hope this answers your question.
. bookface-ga |