Computer Speed Suppose a program has a certain number of statements, which on av
ID: 3772859 • 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) Times (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.Explanation / Answer
Program:
// import the required files
import java.io.*;
import java.util.*;
import java.lang.management.*;
public class computerspeed
{
public static void main(String[] args)
{
// idle process start time
long idealstartTime = System.nanoTime();
// named constands
double SOURCE_CODE = 10000;
double AVERAGE_INSTRUCTIONS= 20.0;
double CLOCK_RATE= 2000.0;
double AVERAGE_INSTRUCTIONS_CYCLE= 1.0;
double FIRST_LEVEL_CACHE_HIT= 0.99;
double FIRST_LEVEL_CACHE_SWAP =0.0010;
double SECOND_LEVEL_CACHE_HIT=0.999;
double SECOND_LEVEL_CACHE_SWAP=0.0050;
double MAIN_MEMORY= 0.9999;
double MAIN_MEMORY_PAGE=4096;
double DISK_SPEED=500.0;
double DISK_TRACK=400000;
// execution process start time
long processstartTime = System.nanoTime();
System.out.println("Assumed executions of source-code statements:"+SOURCE_CODE);
System.out.println("Assumed average instructions/statement:"+AVERAGE_INSTRUCTIONS);
System.out.println("Assumed clock rate in megahertz:"+CLOCK_RATE);
System.out.println("Assumed average instructions/cycle:"+AVERAGE_INSTRUCTIONS_CYCLE);
System.out.println("Assumed first-level cache hit fraction:"+FIRST_LEVEL_CACHE_HIT);
System.out.println("Assumed first-level cache swap time in microsec: "+FIRST_LEVEL_CACHE_SWAP);
System.out.println("Assumed second-level cache hit fraction:"+SECOND_LEVEL_CACHE_HIT);
System.out.println("Assumed second-level cache swap time in microsec:"+SECOND_LEVEL_CACHE_SWAP);
System.out.println("Assumed main memory hit fraction: "+MAIN_MEMORY);
System.out.println("Assumed main memory page size in bytes/page:"+MAIN_MEMORY_PAGE);
System.out.println("Assumed disk speed in revolutions/sec:"+DISK_SPEED);
System.out.println("Assumed disk track length in bytes/revolution:"+DISK_TRACK);
// process end time
long stopTime = System.nanoTime();
// total execution time
long tottime=stopTime-idealstartTime;
// process execution time
long processtime=stopTime-processstartTime;
// idle time
long idletime=tottime-processtime;
// calculated time
System.out.println("Ideal execution time = " +idletime+" nano seconds.");
System.out.println("Expected execution time = " + processtime + " nano seconds.");
}
}
Result:
Assumed executions of source-code statements: 10000.0
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.0
Assumed disk speed in revolutions/sec: 500.0
Assumed disk track length in bytes/revolution: 400000.0
Ideal execution time = 1400 nano seconds.
Expected execution time = 23831454 nano seconds.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.