Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer Speed Suppose a program has a certain number of statements, which on av

ID: 3773105 • Letter: C

Question

Computer Speed

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.

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.

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.

Explanation / Answer

import java.io.*;
import java.util.*;

class main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double statements= 10000,instructions = 20.0, clock_rate = 2000.0, average_cycle = 1.0, first_level_cache = 0.99, first_level_cache_swap = 0.0010, second_level_cache = 0.999, second_level_cache_swap = 0.0050, memory_hit = 0.9999, memory_page = 4096, disk_speed = 500.0, disk_length = 400000;
      
        System.out.print("Assumed executions of source-code statements :   ");
        zstatements = sc.nextDouble();
        System.out.print("Assumed average instructions/statement :   ");
        instructions = sc.nextDouble();
        System.out.print("Assumed clock rate in megahertz: ");
        clock_rate = sc.nextDouble();
        System.out.print("Assumed average instructions/cycle: ");
        average_cycle = sc.nextDouble();
        System.out.print("Assumed first-level cache hit fraction: ");
        first_level_cache = sc.nextDouble();
        System.out.print("Assumed first-level cache swap time in microsec: ");
        first_level_cahce_swap() = sc,nextDouble();
        System.out.print("Assumed second-level cache hit fraction: ");
        second_level_cache = sc.nextDouble();
        System.out.print("Assumed second-level cache swap time in microsec: ");
        second_level_cahce_swap() = sc.nextDouble();
        System.out.print("Assumed main memory hit fraction : ");
        memory_hit = sc.nextDouble();
        System.out.print("Assumed main memory page size in bytes/page: ");
        memory_page = sc.nextDouble();
        System.out.print("Assumed disk speed in revolutions/sec:   ");
        disk_speed = sc.nextDouble();
        System.out.print("Assumed disk track length in bytes/revolution: ");
        disk_length = sc.nextDouble();
      
        double ideal_exec = statements*instructions/ (average_cycle*clock_rate);
        System.out.println("Ideal execution time = "+ideal_exec);
      
        double expected_exec = ideal_exec + (1 - first_level_cache)*first_level_cahce_swap + (1 - first_level_cache)*(1 - second_level_cahce)*second_level_cahce_swap + ((1 - first_level_cache)*(1 - second_level_cahce)*(1 - memory_hit)* (0.5/disk_speed + memory_page/(disk_speed*disk_length)));
System.out.println("expected execution time = "+expected_exec);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote