# Timing issues in windows version

**URL:** <https://psychtoolbox.discourse.group/t/timing-issues-in-windows-version/2053>\
**Category:** Uncategorized\
**Created:** [June 29, 2004, 6:08pm UTC](https://psychtoolbox.discourse.group/t/timing-issues-in-windows-version/2053 "2004-06-29T18:08:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xeos](https://avatars.discourse-cdn.com/v4/letter/x/ecae2f/32.png) [@xeos](https://psychtoolbox.discourse.group/u/xeos)\
**Post date:** [June 29, 2004, 6:08pm UTC](https://psychtoolbox.discourse.group/t/timing-issues-in-windows-version/2053/1 "2004-06-29T18:08:26Z")

</div>

Hi all,  
  
I've observed some strange timing issues when drawing off-screen   
buffers to the screen in Windows. My expectation is that if I wait   
for vertical refresh, and then call CopyWindow, it should take about   
the same number of MS to blit the offscreen window. But this does not   
seem to be the case; it takes either ~1 ms, or ~13 ms, regularly   
alternating between these two as a function of when the offscreen   
buffers were created. Specifically, the first 10 or so offscreen   
buffers can be rendered in ~1ms, and the rest take ~13ms.   
  
I've attached code that reproduces this effect. It creates 100 off   
screen windows, and then draws them a total of 4 time each, and then   
plots how long GetSecs thinks it took to blit them.   
  
The alternating behavior seems to show up on all (2) machines that   
I've been able to test it on.  
  
Of course, 13ms jitter isn't much to worry about, except that I'm   
doing priming experiments and I'd like to have all the noise on the   
side of the human response, and as little on the part of the   
computer...  
  
Any ideas what's going on here?  
  
----------------------------------------------  
  
clear('buffer');   
clear('timePerImage');  
  
%!reschange -width=800 -height=600 -depth=32 -refresh=60  
  
screen('closeall'); % close any orphaned windows  
[window, screenRect] = screen(0, 'OpenWindow', [0 0 0],[],32); %   
create a new window, 32 bit depth  
  
HideCursor; % turn off mouse cursor  
  
for i=1:100 % load images before displaying them on screen  
 buffer(i)=screen(window,'OpenOffscreenWindow',0);  
 screen(buffer(i), 'DrawRect', i\*25, [10,10,780,580]);  
end  
  
screen(window, 'WaitBlanking'); % make sure that waitblanking has   
been called at least once before entering loop  
  
priority(2); % set high priority for max performance  
for index=1:length(buffer)\*4  
 screen(window, 'WaitBlanking'); % wait until refresh blanking  
  
 startAt = GetSecs;  
 screen('CopyWindow', buffer( 1+mod(index,length(buffer)) ),   
window); % draw on screen (hopefully finishing before blanking   
period),   
 timePerImage(index) = GetSecs - startAt;  
end   
  
priority(0);  
screen('closeall');  
  
%!reschange -width=1280 -height=1024 -depth=32 -refresh=85  
  
plot(timePerImage\*1000);  
title('time to draw each frame in ms');  
average\_display\_of\_single\_image\_inMS = 1000\*mean(timePerImage)
