Suppose a program has a certain number of statements, which on average execute many times in repetitions, that is, statementExecutions = (number of statements) x (average repetition count). A compiler translates this into object-code instructions. Since source-code statements often include more than one explicit primitive operation, and there are often many invisible primitive operations in the background, the number of object-code instructions is typically much greater than the number of source code statements. We can represent these effects with the multiplier, instructionsPerStatement.
A processor has a particular speed, clockRate. Although some instructions may require several clock cycles to complete, a modern computer often executes more than one instruction in parallel, so a given program on a given computer has an average instructionsPerCycle that may be either less than or greater than unity. The ideal total execution time is:
statementExecutions x instructionsPerStatement /
(instructionsPerCycle x clockRate ).
To this ideal time, we must add whatever time it takes to fetch information not immediately available. For each successful instruction execution, we must add time to account for the chance of not finding something that’s needed. Not finding something in the first-level cache adds:
(1 – firstCacheHitFraction) x firstCacheSwapTime.
Not finding something in the second-level cache adds:
(1 – firstCacheHitFraction) x (1 – secondCacheHitFraction) x
secondCacheSwapTime.
Not finding something in the main memory adds:
(1 – firstCacheHitFraction) x (1 – secondCacheHitFraction) x
(1 – mainMemoryHitFraction) x
[0.5 / diskSpeed + pageSize/(diskTrackLength x diskSpeed)].
Total incremental time is average incremental time multiplied by: statementExecutions x instructionsPerStatement.
a) Using initialized values:
Write a Java program that estimates the total time to run a typical computer program. Note the 12 “assumed” numeric values in the sample session below. Use 12 initialization statements to store those values into 12 variables. No user input is necessary. The bottom two lines are calculated results.
Sample session:
Assumed executions of source-code statements: 10000
Assumed average instructions/statement: 20.0
Assumed clock rate in megahertz: 2000.0
Assumed average instructions/cycle: 1.0
Assumed first-level cache hit fraction: 0.99
Assumed first-level cache swap time in microsec: 0.0010
Assumed second-level cache hit fraction: 0.999
Assumed second-level cache swap time in microsec: 0.0050
Assumed main memory hit fraction: 0.9999
Assumed main memory page size in bytes/page: 4096
Assumed disk speed in revolutions/sec: 500.0
Assumed disk track length in bytes/revolution: 400000
Ideal execution time = 1.0E-4 seconds.
Expected execution time = 1.0221409599999999E-4 seconds.
b) Using inputs:
Modify the program of part A to make it accept inputs that override the initialized values. Make your program so that what appears on your computer screen matches the following sample session. As always, if a sample session contains italicized values, those values indicate user input.
Sample session:
Enter executions of source-code statements: 10000
Enter average instructions/statement: 20
Enter clock rate in megahertz: 2000
Enter average instructions/cycle: 1
Enter first-level cache hit fraction: .99
Enter first-level cache swap time in microsec: .001
Enter second-level cache hit fraction: .999
Enter second-level cache swap time in microsec: .005
Enter main memory hit fraction: .9999
Enter main memory page size in bytes/page: 4096
Enter disk speed in revolutions/sec: 500
Enter disk track length in bytes/revolution: 400000
Ideal execution time = 1.0E-4 seconds.
Expected execution time = 1.0221409599999999E-4 seconds.
Print a hard copy of the source Code and generated output. Your program should have several runs, i.e. generate several output…the output should be in the format above or if you decide to use NetBeans, runs several copies of the GUI..