yupepa Posted July 4, 2012 Share Posted July 4, 2012 (edited) Hi, while running a script, i sometimes need a short delay. I tried it with sleep, but received a strange behavior depending on the hardware. Just a simple script like $begin = TimerInit() Sleep(5000) MsgBox(0, "Timer", "Duration = "& TimerDiff($begin)) gives a duration of 5004 on a Pentium with 4CPU, 3GHz, on an Intel Core2 Duo, E8400 3GHz differs each time i run the script, but allways much lower, between 200 and 500! Even compiling the script on the second PC didn't change anything???? Funny thing, the real duration is correct, only the output differs Any ideas, do i miss anything??? Regards Paul Edited August 2, 2012 by yupepa Link to comment Share on other sites More sharing options...
bestsmr Posted July 4, 2012 Share Posted July 4, 2012 No yupepa , it`s not strange the result is : pause 5000 as you want + the time for do 3 lines you can try adding more lines and the result will be bigger as this : $begin = TimerInit() Sleep(5000) for $i=1 to 100 $i=$i next MsgBox(0, "Timer", "Duration = "& TimerDiff($begin)) Link to comment Share on other sites More sharing options...
hannes08 Posted July 4, 2012 Share Posted July 4, 2012 I cannot reproduce you problem here. On all PCs I tested the TimerDiff works s designed. @bestsmr: I guess his issue is not the 4ms difference but the fact that his Core2Duo reports 200 - 500 ms instead of 5000 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
yupepa Posted July 5, 2012 Author Share Posted July 5, 2012 One of the outputs .... Regards Paul Link to comment Share on other sites More sharing options...
yupepa Posted July 5, 2012 Author Share Posted July 5, 2012 There should be a screen print... but it seems not to work.... Whats the best way to insert a screenprint??? Paul Link to comment Share on other sites More sharing options...
twitchyliquid64 Posted July 5, 2012 Share Posted July 5, 2012 (edited) Guys, the issues your having are due to the structure of PCs. It is due to structure of the operating system as a "preemptive multitasking system".Ultimately, your computer can only do a set amount of things at once. If your computer is a dual core then it can only do 2 things at once, and so on.So what the OS does is stops your program executing on CPU, and hands over control to another running program. Your program is completely frozen until your turn (timeslice) comes around again and the OS gives your program control of the CPU.What does this have to do with timing? Well if you have a loop to do timing (as you have done above), whats to garrantee that the OS will not take over control before the end? that can completely screw up timing. It can be anywhere between 13ms to 600ms before your program gets control again. Hence timing is broken.Same thing with sleep. Sleep is NOT meant to be a precise measure of timing. If you are using sleep, what you are really saying to the OS is "I dont need the CPU for x milliseconds, do whatever you want and hand it back to me no earlier than x milliseconds."So dont worry about timing. There is nothing you can do to garrantee CPU time and thus garrantee timer are accurate. Edited July 5, 2012 by twitchyliquid64 ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
hannes08 Posted July 5, 2012 Share Posted July 5, 2012 What you're saying is true for results > the 500ms he entered into his sleep() function. I can only guess how the TimerDiff function works: It just compares two timestamps: the actual timestamp and the given timestamp. So the OP states that his script really does the 5000ms sleep but the TimerDiff() reports 200 - 500ms. On the other hand you're right about the accuracy of timing. There's really no guarantee. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
John Posted July 5, 2012 Share Posted July 5, 2012 (edited) On my dual core I sometimes get a return time of less than 50ms smaller than the minimum time defined by Sleep(5000). Nothing so extreme as reported in the OP. 15 runs: 5006.84854272567 4999.54640349575 < 5000.51348143599 5000.50838484605 5000.66128254412 5006.91161302612 5003.10191204942 5005.31000963893 4999.82034520478 < 4999.84391693323 < 4999.81588568858 < 5003.13121744155 4997.92250252759 < 5003.58099150335 5001.60224046094 Edit: I'm also on a 64bit machine. Edited July 5, 2012 by John Link to comment Share on other sites More sharing options...
water Posted July 5, 2012 Share Posted July 5, 2012 I also get results between 4992 and 5005. Values smaller 5000 are possible because of the divergence introduced when converting the integer to the internal binary representation. The result also includes the time the Autoit interpreter needs to parse and execute the statements following "TimerInit" (Sleep, MsgBox, TimerDiff). My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
zpanderson Posted July 5, 2012 Share Posted July 5, 2012 There are a bunch of threads on the accuracy of sleep and timing methods.I found this method to be quite accurate.Func _Sleep($sTime) $timer=TimerInit() Sleep($sTime - 20) Do $tmp = TimerDiff($timer) Until $tmp >= $sTime EndFunc Link to comment Share on other sites More sharing options...
yupepa Posted July 6, 2012 Author Share Posted July 6, 2012 I just tried the direct dll method as described by monoceres$dll=DllOpen("kernel32.dll") $timer=TimerInit() DllCall($dll,"none","Sleep","dword",1000) MsgBox(0, "Timer2", "Laufzeit = "& TimerDiff($timer))the result was nearly the sameWhat is strange to me is that the sleeping time is accurate, only the output of the TimerDiff is not correct. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 6, 2012 Moderators Share Posted July 6, 2012 I really can't believe ya'll are fussing over a -3 to 7 milliseconds of display. Pretty confident if I made a true test myself it'd be even closer. The idea that it is that close overall, to me, is quite impressive. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
yupepa Posted July 6, 2012 Author Share Posted July 6, 2012 No i dont speak about milliseconds, i need a delay of 0,5 to 2 seconds until the GUI is build up completely and i can not use WinWaitActive. By the way i am only curious about the wrong output of TimeDiff, since the time is whithin some milliseconds correct. Sleep (5000) => sleeping time measured about 5s, output TimeDiff => between 200 and 500! Link to comment Share on other sites More sharing options...
trancexx Posted July 6, 2012 Share Posted July 6, 2012 I would need to see exact script you run and exact output you get. I'm not interesed in "betweens" nor parts of the bigger scripts. Also you need to say what version of AutoIt you run that code on and what system you run it on. It would also be nice if other people would stop talking about the wrong and unrelated things. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
yupepa Posted July 6, 2012 Author Share Posted July 6, 2012 The script is as mentioned in the begining of the thread, I just updated Autoit to the latest version 3.3.8.1, on Intel Core2 Duo, E8400 3GHz. Output within the MessageBox as mentioned before, varies between 200 and 500. Link to comment Share on other sites More sharing options...
trancexx Posted July 6, 2012 Share Posted July 6, 2012 Are you stupid person? Did you read my post? Do you want to know what the problem is or not? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
yupepa Posted July 6, 2012 Author Share Posted July 6, 2012 What is your problem? This is the complete script! Do you really want a picture of the messagebox with a number? i attached it. I told you the version and system data! What are you missing???? Link to comment Share on other sites More sharing options...
trancexx Posted July 6, 2012 Share Posted July 6, 2012 Could someone write simple script for yupepa member that would show us what his operating system is, AutoIt version, system bitness, AutoIt bitness, and all other important stuff he should show together with the result of TimerDiff() in one message box that he can take a screenshot of? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 6, 2012 Moderators Share Posted July 6, 2012 Hi, Yupepa. Try something like this to give Trancexx the information she needs. Post the screenshot in your reply, please. $begin = TimerInit() Sleep(5000) MsgBox(0, "For Yupepa", "OS: " & @OSVersion & @CRLF & "Architecture: " & @OSArch & @CRLF & "AutoIt Ver: " & @AutoItVersion & @CRLF & "Duration = " & TimerDiff($begin)) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted July 6, 2012 Share Posted July 6, 2012 Add the AutoIt bitness: $begin = TimerInit() Sleep(5000) MsgBox(0, "For Yupepa", "OS: " & @OSVersion & @CRLF & "Architecture: " & @OSArch & @CRLF & "AutoIt Ver: " & @AutoItVersion & @CRLF & "@AutoItX64: " & @AutoItX64 & @CRLF & "Duration = " & TimerDiff($begin)) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now