Empirical Performance
Empirical Performance
int main() {
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
int i;
for(i = 0; i < 1000; ++i)
printf("How fast is 1000 printfs? \n");
gettimeofday(&tv2, NULL);
Adapt the above code so that you can see how long it takes to execute a certain number of push operations
on a given implementation of stack. Be sure to test things out and make sure everything is working
properly before collecting data. Make sure that you don’t call any printf statements within the body of the
for loop, since that will ruin your timing data. When you are ready collect the timing data for the
following, and enter it into the common spreadsheet provided:
1. Create your own small table in Excel that contains the timing data you just recorded. Then, use its
built-in graph plotting tools to create two line graphs on the same set of axes, one for each
implementation, with the number of pushes on the x-axis, and the number of seconds to execute on
the y-axis.
2. Create another table, similar to the one above, where you show the average amount of time taken
for each push in each of the trials shown in the original table. To do this, you simply divide the total
amount of time taken by the number of pushes for that particular trial. Create a second double-line
graph that summarizes the information in this table.
3. Now, try answering the following questions:
a) How would you characterize the growth in the graphs above, e.g., constant, linear, logarithmic,
quadratic, something else?
b) Compare the results of the two implementations, side by side. Do these results surprise you?
Why or why not? Can you explain why the results are the way they are?
c) For the array-based stack implementation, for the full value of N =1,000,000, approximately how
many times was the value array of the stack resized?
d) Which of these implementations seem to be a better choice for storing large amounts of data in
terms of time efficiency? Does this answer surprise you?