I ran into a phenomenon that I don't understand.
Basically it goes like this. If I run this code, it displays the frequency the loop cycles. It is a very high frequency if the SLEEP is 0 or is omitted. If it is SLEEP 1 (ms), it should be nominal 1000Hz while SLEEP 2 it's 500Hz.
However, the frequency varies from machine to machine. On my vista laptop with dual core, it runs at 64Hz nominal until I run Firefox on a page that has graphics - it then runs at the predicted frequency. Closing Firefox causes it to return to 64Hz. MSIE however doesn't have the same effect, nor does opening Firefox to a local jpg file. I also found if I open and run my DVD player or other prog that uses DirectX video, the speed goes to where it should.
On my wife's XP laptop it runs at 171 Hz regardless of other apps running. On another machine with no other progs running it shows predicted speed.
Any ideas? Virus infection? Spyware?
Anyway, here's the code.... can anyone else replicate?
Basically it goes like this. If I run this code, it displays the frequency the loop cycles. It is a very high frequency if the SLEEP is 0 or is omitted. If it is SLEEP 1 (ms), it should be nominal 1000Hz while SLEEP 2 it's 500Hz.
However, the frequency varies from machine to machine. On my vista laptop with dual core, it runs at 64Hz nominal until I run Firefox on a page that has graphics - it then runs at the predicted frequency. Closing Firefox causes it to return to 64Hz. MSIE however doesn't have the same effect, nor does opening Firefox to a local jpg file. I also found if I open and run my DVD player or other prog that uses DirectX video, the speed goes to where it should.
On my wife's XP laptop it runs at 171 Hz regardless of other apps running. On another machine with no other progs running it shows predicted speed.
Any ideas? Virus infection? Spyware?
Anyway, here's the code.... can anyone else replicate?
Code:
#COMPILE EXE #DIM ALL #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF GLOBAL qFreq AS QUAD GLOBAL qStartCount AS QUAD GLOBAL qEndCount AS QUAD FUNCTION InitHiresTimer() AS DWORD CALL QueryPerformanceFrequency(qFreq) END FUNCTION MACRO startHiresTimer CALL QueryPerformanceCounter(qStartCount) END MACRO FUNCTION display_loopfreq() AS STRING QueryPerformanceCounter(qEndCount) FUNCTION = FORMAT$(qFreq/(qEndCount-QStartCount),"#.0")+" Hz" QueryPerformanceCounter(qStartCount) END FUNCTION 'THREAD FUNCTION loopthread(BYVAL x AS DWORD) AS DWORD 'pbwin9 FUNCTION loopthread(BYVAL x AS DWORD) AS DWORD initHirestimer() startHiresTimer() DO SLEEP 2 'compare with sleep 1, sleep 0, dialog doevents DIALOG SET TEXT x, display_loopfreq() LOOP UNTIL gThreadrun = 0 END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL x AS DWORD LOCAL hdlg AS DWORD LOCAL hThread AS DWORD DIALOG NEW %HWND_DESKTOP, "", 0,0, 100,0 TO hdlg DIALOG SHOW MODELESS hDlg GLOBAL gThreadrun AS DWORD gThreadrun = 1 THREAD CREATE loopthread(hdlg) TO hThread THREAD CLOSE hThread TO hThread MSGBOX "Quit?",,"Loopspeed" 'This holds loop running until msgbox closes gThreadrun = 0 END FUNCTION
Comment