0% found this document useful (0 votes)
12 views2 pages

Empirical Performance

This document provides instructions for an assignment to collect and analyze timing data from running push operations on two different stack implementations - an array-based stack and a linked list-based stack. Students are asked to time push operations for various numbers of pushes, enter the timing data into a shared spreadsheet, and answer questions about graphs of the results to characterize performance and growth trends for each implementation.

Uploaded by

Shammï Yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Empirical Performance

This document provides instructions for an assignment to collect and analyze timing data from running push operations on two different stack implementations - an array-based stack and a linked list-based stack. Students are asked to time push operations for various numbers of pushes, enter the timing data into a shared spreadsheet, and answer questions about graphs of the results to characterize performance and growth trends for each implementation.

Uploaded by

Shammï Yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSCI 501/701 – (Advanced) Software Principles and Practice Fall 2023

Empirical Performance – Exercise and Questions

Due Date: Wednesday, September 27, before class, i.e. 14:30


For this mini-assignment, you will run timing tests of your two stack implementations from Assignment
2, and answer some questions. You will need to enter in your answers into the Google Sheets spreadsheet
provided for the whole class. It is important that you do this before the deadline, as we will use
everyone’s results as a basis for in-class discussion on Wednesday.

Collecting Timing Data


To find the time that it takes to execute a particular sequence of operations, you can use a program like
the following (adapted from: https://stackoverflow.com/questions/5248915/execution-time-of-c-
program):
#include <sys/time.h>
#include <stdio.h>

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);

printf("Total time = %f seconds\n",


(double) (tv2.tv_usec - tv1.tv_usec) / 1000000
+ (double) (tv2.tv_sec - tv1.tv_sec));
return 0;
}

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:

• For an array-based stack:


o 15 million pushes, 30 m pushes, 45 m pushes, 60 m pushes, 90 m pushes,
• For a linked list-based stack:
o 15 million pushes, 30 m pushes, 45 m pushes, 60 m pushes, 90 m pushes,
Questions to Answer
Now, do the following on your own. Write your answers to #3 on a piece of paper, and bring it in to
class on Wednesday – you may be asked to turn it in!

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?

You might also like