Got asked in an interview. They asked to order the following in terms of speed:
pretty sure the disk seek is the slowest and register access is the fastest, but not quite sure about the two in between. Can anyone explain it a bit?
A fast context switch is performed, whenever a functional unit comes across an operation destined for another unit. Switching contexts on each load/store instruction sequence allows a much faster context switch in the execution unit than previously published designs do.
The disadvantage of context switching is that it requires some time for context switching i.e. the context switching time. Time is required to save the context of one process that is in the running state and then getting the context of another process that is about to come in the running state.
Context switches between threads are faster than between processes. That is, it's quicker for the OS to stop one thread and start running another than do the same with two processes. A context switch between processes is heavy.
Each context switch takes the kernel about 5 μs (on average) to process. However, the resulting Cache misses add additional execution time that is difficult to quantify. The more frequent the context switches, the more your CPU utilization degrades.
I happened to find a surprisingly good answer on Yahoo!:
Fastest to slowest:
- CPU
- Memory
- Context switching
- Disk
Although:
Disk access may be significantly faster at times due to caching ... so can memory access (CPUs sometimes manage a caches from main memory to help speed up access and avoid competition for the bus).
Memory access could also be as slow or slightly slower than disk access at times, due to virtual memory page swapping.
Context switching needs to be extremely fast in general ... if it was slow then your CPU could begin to spend more time switching between processes than actually performing meaningful work when several processes are running concurrently.
Register access is nearly instantaneous.
(emphasis mine)
I agree with that answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With