Average Print Time

iced107

New member
Joined
Oct 30, 2013
Messages
1
Having trouble with a lab - I've already been given an extension and I am still struggling to figure it out.

Assume the following:
a. Disk spooling is NOT being used.
b. The printer does NOT have a hardware buffer to hold the output while the printer is printing
(The theme music from Mission Im possible is playing faintly in the background).
SIMULATE the following scenario
A hypothetical program computes for three seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)
The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer. Plot the results (by hand is OK). The Y axis is from zero to 8 seconds, and the X axis is nonlinear and displays all nine cases of buffers.

Here is my current coding in python:

import random
import Queue


q = Queue.Queue()
print("This program simulates a printer printing records while dealing with interrupts over 9 different buffers.")
print("Number of Loops: 500")
print("Number of Buffers: 9")
print("Record Generation Time: 3")
print("Minimum/Maximum print time: .075/4.75")


def main(q):
buffers= [0,1,2,3,4,5,10,25,100];
for buffer in buffers:
sum = 0
for i in range (1, 500):
q.put(i)
time= (random.uniform (0.75,4.75)+3)
sum = sum + time;
average= (sum/500);
while not q.empty():
q.get()
print("For Buffer",buffer,",the average time is",average,".");
main(q)

and here is something i've been playing with.


import random
import Queue


q = Queue.Queue()
print("This program simulates a printer printing records while dealing with interrupts over 9 different buffers.")
print("Number of Loops: 500")
print("Number of Buffers: 9")
print("Record Generation Time: 3")
print("Minimum/Maximum print time: .075/4.75")


def main(q):
buffers= [0,1,2,3,4,5,10,25,100];
for buffer in buffers:
sum = 0
for i in range (1, 500):
q.put(i)
time= (random.uniform (0.75,4.75)+3)
sum = (sum + time);
average =(sum - (buffer * 3))/500;
while not q.empty():
q.get()
print("For Buffer",buffer,",the average time is",average,".");
main(q)

I still can't figure it out - I know I am doing it wrong because 0 buffer is supposed to return around 5.75'ish (which it does), however the 100 buffer is supposed to be in the low 3's. I've reached out to a lot of different places and I feel like I get the concept; however my coding is pretty weak and I'm not quite sure how to make the translation. I understand the buffers allow it to go quicker and process more jobs without waiting in a Queue (hence the FIFO queue); coding that is a different story.

Believe it or not this is the only coding in this class on top of it; however we were supposed to have a lot of coding before this class, which i was never informed was a prerequisite until my professor told me a week or 2 ago, and that doesn't help me at this point because it's already a week into the semester. I'm trying to make due with what I can, this was not the situation I wanted to be put in nor can I do anything about it.
 
Last edited:
Top