To compare the performance of adding to Java's Linked Lists vs. Array Lists
For this Lab, you will be writing code to compare the performance of adding data to Java's built-in LinkedList and ArrayList classes. We will be adding data to the beginning and end of both of these data structures and timing how long it takes to run these programs.
In order to test how long a program takes to run, we will see what time it is at the very start of the program, and then again at the very end. We will then subtract these two values which gives us the amount of time that has elapsed.
We can get a time reading with the
long startTime = System.nanoTime();
This returns a value in nano-second units, so it should be put in a long variable. That should be done at the very start of main, before anything else. Then at the end of the program, we take another time reading:
long endTime = System.nanoTime();
We can then compute the difference between them. We will also convert to milliseconds by dividing by 1000000:
long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds.");
For this lab, you can fill out the following table of times:
Also, answer the following questions:
When you're finished, submit the table, along with your answers to the three questions on Canvas. You can either just enter text for your submission, or upload a document.
Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.