All non-programming and programming problems in this assignment are to be done by yourself. Group collaboration is not permitted for this assignment. Each of you should turn in one hardcopy for the non-programming problems and one hardcopy for the programming problems. Both hardcopies should have your name and email address clearly written on the first page.
gettsc
that takes a
pointer to a long long as an argument and has a return type
of void. Test your function by using it in a program to measure
the time it takes to execute each iteration of the following
inner for loop:
Report your results for N=10, 100, 1000, 10000, and 100000. Plot your results across the 100 iterations and report the average and standard deviation of your measurements for each value of N.for (i=0; i<100; i++) { for (j=0; j<N; j++) { /* inner loop starts here */ k = i + j; } /* inner loop ends here */ }
gettsctime
that
takes a long long tsc value as an argument and returns the
equivalent long long in nanoseconds. Repeat the tests from
part a, this time reporting the results in nanoseconds. Your
function should be portable across machines, so it will need
to determine the CPU speed of the machine on which it is being
called. One way to do this in Linux is to parse the data
contained in the file /proc/cpuinfo. The /proc filesystem
(where /proc/cpuinfo resides), is a virtual filesystem that
presents a way for userspace to communicate with the kernel
and vice-versa. Various statistics can be read from the files
in the /proc filesystem and /proc/cpuinfo, as its name
suggests, contains information regarding the CPU.
gettimeofday
to measure the
performance of the same set of for loops. Compare and discuss
any differences in the measurements between these results and
those from part b.
gettsc
, gettsctime
,
and gettimeofday
? Write a program to do determine this. You
should be careful to do the measurement in such a way that the
overhead of doing the measurement is negligible.