The answer Should be 10.2
1 Keystroke per second.
- Polling System (T1)
CPU Polls (ask) keyboard every 10 ms and asks did you get any keystrokes.? Keyboard Answers “Yes” only once per second.
In One second, the CPU Polls the Keyboard 100 times (1 Sec = 1000 ms, and the CPU polls every 10 ms).
Time Spent in Polling = 100 * 100microsec = 10000 microseconds or 10 milesec.
Time Spent in Processing the Keystroke (Only once per second) = 200microsec or 0.2 milisec.
CPU’s Time wasted in Polling System = Time Spend in Polling + Time Spent in Processing = 10.2 ms
- Interrupt System (T2)
CPU doesn’t ask Keyboard periodically about the keystroke, but Keyboard tells CPU via interrupt about a Keystroke.
Whenever, there is a keystroke, Keyboard interrupts CPU. CPU Executes corresponding Interrupt Service Routine (ISR) which takes 1ms. Thats all.
Speed Up of Interrupt over polling system (S) = T1/T2 = 10.2 ms / 1 ms = 10.2
Example:
Let's consider Rubina is personal assistant of Pathaan; Pathaan assigns some tasks to Rubina. Now Pathaan is a very busy man and his every minute is very important.
Pathaan needs the status of the work that he assigned to Rubina. Pathaan can take the status of the work in two ways:
- Using Polling System
- Using Interrupt System
If Pathaan uses Polling System, Pathaan will keep asking Rubina about the status of the work every 10 ms. 100 microsec of Pathaan are wasted in talking to Rubina, but Rubina answers Yes only once a second, If Rubina answer Yes then Pathaan spends another 200 microsec to review the work done by Rubina. So in this case Pathaan waste 100*100 microsec in talking to Rubina (Because he calls her every 10 ms and spends 100 microsec in talking so in one sec he waste 100*100 Microsec). Rubina completes work only once per second (Means she answers Yes only once out of 100 times that Pathaan asks in 1 sec). If Rubina answer Yes, Pathaan spends another 200 microsec to review the work done by Rubina. So Total time wasted by Pathaan is 10 ms + 0.2 ms.
- Better approach will be : Pathaan Assign work to Rubina and sits back and wait for Rubina to tell him work is done. (Rubina Interrupts Pathaan). Rubina interrupts Pathaan once per second and Pathaan spends 1 ms in reviewing the work . (So Lots of time saved of Pathaan)
So, We can say second approach is 10.2 times faster than first approach.
Pathaan == CPU
Rubina == Input/Output.