How to calculate throughput of a process scheduling algorithm

2k views Asked by At

I'm trying to calculate throughput of FCFS algorithm using Java, however it always gives me zero. Am I doing it right?

    startTime = System.nanoTime();

    total = FCFC(copyBurstTime, copyArrivalTime);

    estimatedTime = System.nanoTime() - startTime;

    throughput = (float)(5 / estimatedTime);

where FCFS returns two int values total avg. waiting time and total avg. turnaround time, and 5 is the number of processes. throughput variable is of type float. Say estimatedTime = 6844

1

There are 1 answers

0
Scary Wombat On BEST ANSWER

this is caused by Integer division.

try this instead

    long startTime = System.nanoTime();
    long estimatedTime = startTime + 1000;

    float throughput = (float) (5.0 / estimatedTime);
    System.out.println(throughput);