Version 61
Code listings, handouts: Three Algorithms for Analysis
System.currentTimeMillis() (see TimeTest.java, Fig. 7-1 and 7-2, pp. 184–185).get method than the LinkedList class, and that in the latter, get(i) has time proportional to i; but "a couple of data points are not really a convincing case."The Linux shell command time can also be used to measure the time to run a program:
$ java TimeTest
ArrayList: 7 milliseconds
LinkedList: 22 milliseconds
$ time java TimeTest
ArrayList: 7 milliseconds
LinkedList: 51 milliseconds
real 0m0.234s
user 0m0.111s
sys 0m0.020s
The program's CPU time is user + sys. (sys is the time spent by the operating system on behalf of the program.) This includes time to start the Java program running (start up Java Virtual Machine, load classes), so it is larger, but it does not include time during which the CPU works on other processes (which real time does).