title: Execution time: GetFrontBufferData, GetBackBuffer, GetRenderTargetData
body: <p>I'm trying several methods to capture screen with DirectX and I've come up with 3 methods so far:</p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174388%28v=vs.85%29.aspx" rel="nofollow"><code>GetFrontBufferData()</code></a> - Average execution times:
  <ul>
  <li><code>GetFrontBufferData()</code>: <em>0.83598 s</em></li>
  <li><code>D3DXSaveSurfaceToFile()</code>: <em>0.0036 s</em></li>
  <li>Total: <strong>0.83958 s</strong></li>
  </ul></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174379%28v=vs.85%29.aspx" rel="nofollow"><code>GetBackBuffer()</code></a> - Average execution times:
  <ul>
  <li><code>GetBackBuffer()</code>: <em>0 s</em> <strong>&lt;-- INTERESTING - WHY?</strong></li>
  <li><code>D3DXSaveSurfaceToFile()</code>: <em>0.2918 s</em></li>
  <li>Total: <strong>0.2918 s</strong></li>
  </ul></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174405%28v=vs.85%29.aspx" rel="nofollow"><code>GetRenderTargetData()</code></a> - Average execution times:
  <ul>
  <li><code>GetRenderTargetData()</code>: <em>0.00928 s</em></li>
  <li><code>D3DXSaveSurfaceToFile()</code>: <em>0.00354 s</em></li>
  <li>Total: <strong>0.01282 s</strong></li>
  </ul></li>
  </ul>
  
  <p>Average times have been computed by taking 50 screenshots and by measuring time with <a href="http://www.cplusplus.com/reference/ctime/clock/" rel="nofollow"><code>clock()</code></a>.</p>
  
  <p>All the methods above work, however, as you can see, execution times vary a lot from one method to another <em>for the same results</em> (apparently).</p>
  
  <p>So I have a few questions:</p>
  
  <ul>
  <li>Why the execution time differs so much from one method to another?</li>
  <li>Why is <code>GetBackBuffer()</code> very fast but then <code>D3DXSaveSurfaceToFile()</code> is very slow?</li>
  </ul>
  
  <p>I have an hypothesis about my first question, correct me if I'm wrong:</p>
  
  <ul>
  <li><code>GetFrontBufferData()</code> is very slow because the front buffer is in the VRAM and it's locked/protected because that's what's currently displayed to the screen.</li>
  <li><code>GetBackBuffer()</code> (and <code>D3DXSaveSurfaceToFile()</code>) is faster because the back buffer is in the VRAM but it's not currently displayed to the screen, so it's easier to retrieve.</li>
  <li>Finally, <code>GetRenderTargetData()</code> is fast because the render target is in the system ram (not in the VRAM) so we can retrieve it very fast.</li>
  </ul>
  
  <p>Thank you.</p>
  
  <p>EDIT: I'm still looking for an answer.</p>