Task 2.1 - Random Array Fill Timings

In this task you will learn how to measure execution time of codes in java over various problem sizes. This is in preparation for measuring the execution time of various algorithms.
  • Write a simple class "RandomArray" which constructs objects consisting of an array of N random integers. N should be an argument to the constructor and the constructor should create the array as a data member of the class. Also provide a method to print out the elements of this array on the terminal in the sequence they are stored.
    •  For integer generation you may use the Random class from java.utils or the Math.random method. For other languages you have to consult the documentation to find a suitable random number generator.
  • Write a class MeasureTime with only a main function which measures the time it takes to fill the array with N values for various values of N (say for 100, 200, ..., 1000 - you may need larger array sizes to show the scaling behaviour better) and prints out the size of the array and the time on the terminal in CSV format. For this you simply need to use a for loop over the values of N to test it, start timing inside the for loop, then create a RandomArray of size N, measure the time afterwards and then print out the difference as N,time on STDOUT, one result per line.
  • Then measure the time by running "java MeasureTime >timing.csv" (or equivalent in other languages) and load the generated csv file into a spreadsheet programme (such as libreoffice, gnumeric, ...; if you want to use matlab write the timings as a matlab matrix instead of a csv file). Note that you can use this as a framework to time all kinds of algorithms for a single problem size parameter N (more parameters require nested for loops or testing each parameter individually). You should repeat the time measurement for a particular value of N a few times and take the average to obtain more robust timings (put another for loop around the start timer/execute/end timer block, add up the times and print the average afterwards; make sure the time measurement is done inside the repeat-loop, as otherwise you are also measuring the loop execution, not just the execution of the code-block of interest).

Once you have the resulting measurements please upload the time plot here to show you have completed the task and provide a short comment indicating the time complexity the graph shows in the text field.