// CSE 143, Winter 2010, Marty Stepp // This program performs some operations on a Stack collection and // measures and reports the total runtime. // It forms a basis for runtime efficiency testing that we'll do in later lectures. import java.util.*; public class SpeedTest { public static void main(String[] args) { // get start/stop system times to find out how fast the code ran long startTime = System.currentTimeMillis(); Stack s = new Stack(); s.push(42); for (int i = 0; i < 10; i++) { s.push(i); } System.out.println(s); // bottom 42, 0, 1, 2, 3, ......, 10 top while (!s.isEmpty()) { // pop, peek int topElement = s.pop(); System.out.println(topElement); } System.out.println(s); long endTime = System.currentTimeMillis(); long elapsed = endTime - startTime; System.out.println("Took " + elapsed + "ms"); } }