lab12timing_ProblemSet - CS100J Name _ Section time _...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS100J Lab 12. Timing execution Spring 2008 Name _____________________ NetId __________ Section time _______________ Section instructor ___________________ Introduction The goal of this lab is to show you how to time execution of a program and, with this new skill, to investigate the difference in execution time between linear search and binary search and between selection sort and insertion sort. Have a blank sheet of paper ready, to write on. Start a new folder for the .java files for this program and download these files from the Course web page for labs: Sorting.java TestArrays.java Step 1. Learn about class Date Package java.util contains a class Date , which can be used to record the current time. An instance of this class records a date in milliseconds (there are 1,000 milliseconds in a second) since 1 January 1970 (Greenwich mean time). Since there are 24 * 60 * 60 = 86400 minutes in a day, that's a lot of milliseconds since 1 January 1970! So, use type long to record such a number. To see how this class is used, turn to method times in class TestArrays . The body includes two statements: // Store in timeStart a Date with the time at which the statement is executed. Date timeStart= new Date(); // Store in timeEnd a Date with the time at which the statement is executed. Date timeEnd= new Date(); The next set of statements prints the values of these times in two forms. First, using method toString of class Date (applied automatically); second as an integer, which is obtained using
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

lab12timing_ProblemSet - CS100J Name _ Section time _...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online