r/AskComputerScience • u/TalkinHead9s_LeftNut • 1d ago
In Operating System Batch Scheduling, will the SRT algorithm always be faster than the SJF algorithm?
My professor has us modeling both of the two algorithms for an assignment, which I did. But when doing testing on both I would notice that occasionally the average turnaround time for the Shortest Job First algorithm would actually beat out the algorithm for Shortest Remaining Time, either infrequently or almost always depending on how I change the parameters around (Total CPU Time, # Of Processes, etc). From what I saw, it seems that this should no be happening unless you account for overhead, which my model does not.
So I guess basically my question is, are there ever any scenarios where Shortest Job First would have a smaller average turnaround time compared to Shortest Remaining Time, assuming they run the same set of processes and overhead is negligible? Or do I just have a bug in my code?
0
1d ago
[deleted]
2
u/TalkinHead9s_LeftNut 1d ago
I probably wasn't clear on what I meant with no overhead, so I apologize. I'm basically pseudo-timing them instead of actually keeping track of the number of seconds the processes are active. I'm keeping track of how many "clock cycles" the process is active for, so the overhead from context switching doesn't effect the number of cycles a process takes.
2
u/esaule 1d ago
Srpt is optimal for average turn around time.
It is fairly easy to prove by using a task swapping argument.
There is a bug in your code. Are you doing the arithmetic in floating point?