title: How can I measure the approximation of the time spent in a process context switch?
body: <p>Is there any possibility to measure the approximated time of a process context switch in C#? 
  If yes, how?</p>
  
  <p>I made this question based on the book <a href="https://rads.stackoverflow.com/amzn/click/com/098478280X" rel="nofollow noreferrer" rel="nofollow noreferrer">Cracking the Coding Interview: 150 Programming Questions and Solutions</a>. </p>
  
  <p>Their solution is:</p>
  
  <p>Assume there are only 2 process, P1 and P2. (Is a huge approximation, I believe there are more accurate ones)</p>
  
  <p>P1 is executing and P2 is waiting for execution. At some point OS must swap P1 and P2 - let's assume it happens at the Nth instruction of P1. So the context switch time for this would be:</p>
  
  <pre><code>Time_Stamp(P2_1) - TimeStamp(P2_N)
  </code></pre>
  
  <p>One of the problems is that we cannot record the timeStamp of every instruction in the process. 
  And we don't consider the spending time of the context switch between other processes.</p>