Objective Questions Bibliography Materials and Equipment Experimental Procedure Variations
The goal of this project is to compare how long it takes to perform various mathematical operations with different variable types.
Introduction
Computer technology keeps advancing at an amazing pace. Today's home computers have more memory, run faster and are relatively less expensive than computers from ten or even five years ago. Is there a way to measure how fast your computer is? You might think that you could tell simply from the processor clock frequency, but this doesn't tell the whole story. The clock frequency just tells how many operations per second the CPU can perform. In modern multi-tasking operating systems, the CPU's time is split between many programs running at once. Also, the central processor (CPU) sends data to and receives data from other subsystems on the computer (e.g., memory, disk drives, video display) which usually run at slower speeds. Modern processors are equipped with high-speed data buffers (called caches) to alleviate these bottlenecks. There are also many strategies for optimizing the order of operations in a program for greatest efficiency.
In this project you will use a Java applet (see Experimental Procedure, below) to measure how long it takes for the computer to perform arithmetic operations (addition, subtraction, multiplication and division) with various data types (integers, long integers, floating point numbers and double-precision floating point numbers).
Measuring how long an operation takes provides useful information, both for optimizing algorithm performance, and also as a "benchmark" comparison between two computers. However, you must keep in mind that with today's multi-tasking operating systems, measuring the execution time of any single process is difficult. The operating system splits CPU time between all of the programs that are running. No program has "exclusive" access to the CPU. Generally, CPU processing speed is fast enough so that you don't notice this because programs appear to be instantly responsive. Behind the scenes though, each program is getting a slice of CPU time, then waiting for its next turn before it can run again.
So it is important to remember that, due to multi-tasking, the processing times you measure with the applet below will not represent the actual CPU time required to perform an addition or subtraction. In order for the applet to give you a best estimate, keep the number of open applications to a minimum, and make sure that any open applications are not performing tasks that require lots of CPU time (e.g., printing files or downloading content from the Internet).
How the Timing Applet Works
The applet works by repeating the arithmetic operations within two nested loops. In the inner loop, the program steps through an array (of the chosen data type: int, long, float or double) of 10,000 elements. The chosen operation (addition, subtraction, multiplication or division) is performed by pairing array elements: one counter (index "j", in the code snippet below) starts at the beginning of the array and counts up, the other (index "k" in the code snippet below) starts at the end of the array and counts down. Thus, the inner loop performs the chosen operation 10,000 times.
The outer loop (index "i" in the code snippet below) counts how many times the inner loop should be executed. The default choice is 10,000 times, which means that the arithmetic operation will be performed 10,0000 × 10,000 or 108 times.
The time it takes to execute these two nested loops is measured by the two calls to the Date().getTime() method, which returns the time with millisecond resolution. By subtracting startTime from endTime, the program determines how many milliseconds it took to execute the two nested loops. Again, it is important to remember that the operating system does not give the applet exclusive access to the CPU. The total time measured will also include some time that the operating system allocated to other programs while the applet was running. This is unavoidable, but do your best to minimize the number of other programs running.
startTime = new Date().getTime(); for(int i = 0; i < j =" 0," k =" nElements" endtime =" new">
The applet is written in the Java programming language, which includes four different "primitive" data types for representing numbers: int, long, float and double. The "int" data type uses 32 bits to represent an integer, while the "long" data type uses 64 bits. So the "long" type can represent numbers with larger magnitude than the "int" type, but at the cost of taking up twice as much space, and perhaps taking longer time to process at the CPU. (You'll find out when you make your measurements.) Similarly, the "float" type is a 32-bit decimal number, while the "double" type is a 64-bit decimal number. Which data type do you predict will be processed most quickly? Which do you predict will be processed most slowly?
The two non-arithmetic operations, "no op" and "assign", can be used to calculate the loop "overhead" (the time the program spends incrementing and decrementing the loop variables, and assigning the result to the output array). In the "no op" case, there is an empty statement (literally no operation) in the inner loop. In the "assign" case, a constant value is copied to each member of the output array.
The controls of the applet are self-explanatory (including pop-up "tool tips" that display when the mouse hovers over a control). The "Run" button executes the currently chosen operation. Be careful not to set the number of iterations too high, or you'll be waiting a long time for it to finish. Rememeber that this is the count for the outer loop, and that the actual number of operations performed will be 10,000× this number (since there are 10,000 array elements to cycle through for each iteration of the outer loop).
The text box will show a report of all of the tests you've run. It will display the operation performed, the total number of operations (outer loop count × inner loop count), the total time this took (in milliseconds, abbreviation: ms) and the time per operation (in nanoseconds, abbreviation: ns). The time per operation is calculated by dividing the total time by the number of operations.
Terms, Concepts and Questions to Start Background Research
To do this project, you should do research that enables you to understand the following terms and concepts:
What is the lowest number that can be represented in 32 bits using twos complement notation? In 64 bits?
What is the highest number that can be represented in 32 bits using two complement notation? In 64 bits?
What is the clock period for a processor that runs at 2.4 GHz?
Wikipedia contributors, 2005. "Primitive types". Wikipedia, The Free Encyclopedia [accessed January 6, 2006] http://en.wikipedia.org/w/index.php?title=Primitive_type&oldid=29101932
Wikipedia contributors, 2005. "Floating point". Wikipedia, The Free Encyclopedia [accessed January 6, 2006] http://en.wikipedia.org/w/index.php?title=Floating_point&oldid=33961235
Wikipedia contributors, 2005. "Two's complement". Wikipedia, The Free Encyclopedia [accessed January 6, 2006] http://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=32853980
Wikipedia contributors, 2005. "Benchmark (computing)". Wikipedia, The Free Encyclopedia [accessed January 6, 2006] http://en.wikipedia.org/w/index.php?title=Benchmark_%28computing%29&oldid=32439222
Click on the output text area.
Type
Type
Finally, switch to your spreadsheet application and paste from the clipboard.
Labels: Projects
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment