ripdad Posted June 16, 2020 Share Posted June 16, 2020 (edited) Before I get started, I'm aware of "NtDelayExecution". It doesn't work very good for me. But this does... For $i = 1 To 100 Sleep(0) Next I'm trying to delay a call to a function in nanoseconds with another function in a loop. My question: Is there a safe and efficient function to do this with? Sleep(0) seems to work, but I wondered if someone might know of a better function or perhaps another way. Thanks for any constructive input or thoughts! --Edit-- My target is about 250ns. Anywhere in there would be fine. Edited June 16, 2020 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Dan_555 Posted June 16, 2020 Share Posted June 16, 2020 (edited) Hmm, i wrote a sleeper function, for this post: Mouse Recorder , to be able to access the tray menue while using sleep/delay. Maybe you could use it instead of sleep ? 1000 for the $nr should be 1 second. Func Sleeper($nr) Local $varTS = _Timer_Init() While _Timer_Diff($varTS) < $nr ;CheckTray() WEnd EndFunc ;==>Sleeper Edited June 16, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
TheXman Posted June 16, 2020 Share Posted June 16, 2020 55 minutes ago, ripdad said: My target is about 250ns. Given that AutoIt is an interpreted language, I seriously doubt that you can get anywhere near a 250ns pause. On a 64-bit Windows 7 Pro OS, with an Intel i5 @ 3.1ghz, and no other apps running (only services), the following lines yield around a 4500ns diff. That is just the time it takes to initialize a timer and then do an immediate time difference. So in a loop, and depending on what else is running on the PC, the results would be an even bigger difference. Another way to look at is that you are most likely seeing a bigger pause than 250ns when you execute your commands back to back, without any Sleep function. $hTimer = TimerInit() $nDiff = TimerDiff($hTimer) MsgBox(0, "", "msecs = " & $nDiff & @CRLF & "nsecs = " & ($nDiff * 1000000)) Earthshine 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 Read this page: https://docs.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps Yet beware that the overhead implied by at least two AutoIt calls to any API could waste much more time than the period you aim to tick. Maybe devolve such task to machine code, inline or from a DLL. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ripdad Posted June 16, 2020 Author Share Posted June 16, 2020 Thanks for all your reply's. I really do appreciate it. I fear that reading any value with consolewrite or msgbox would slow it down even further. I have been playing with it some more and found that this is sufficient enough for me. For $i = 1 To 2 Next Although, I have no idea what the reading would be without a literal read. But, it works good enough. That's all that matters. Thanks again! "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2020 Moderators Share Posted June 17, 2020 ripdad, This thread might be of interest for you: M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ripdad Posted June 17, 2020 Author Share Posted June 17, 2020 Thanks Melba23. I did try ZwDelayExecution and NtDelayExecution. I didn't have good luck with either of them. Not sure why at this point --- I played with it some more and found that time is less a factor than another variable. So, what I wanted was a way to expand an audio waveform live in as close to realtime as I could. I knew I couldn't achieve realtime. This graphic is as close as I could come to it without losing coherency of it... I had a very hard time taking a screenshot of it. It was going by so fast! This graphic may not mean much to most people, but to me, this is amazing to see it LIVE. Every musical note with its time duration. And the detail is astounding. --- There's an old saying: "there a hole in everything" -- And I found the hole that I was running into by accident. Do you think music has holes in it? Well, not literal holes -- rather silence. In other words, zero volume. And It does. More than most people know. This silence is what was tripping me up. Why does music have silence? Two factors -- 1. natural and 2. unnatural. These days, everything is digitally encoded. If you understand how they achieve that, then you'll understand what I'm saying. I'm not going explain it here -- it would take too long. --- What I wound up doing is cutting the bottom 3% of the volume out, which gets lost in the envelope anyways. And what do you know? I works! It does come at a CPU cost of about 50%. But well worth seeing. In the end, the function call is in a While loop with nothing else. Time is whatever it takes to complete the waveform function. Thanks everyone and have a good day! "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
ripdad Posted June 17, 2020 Author Share Posted June 17, 2020 (edited) This graphic shows what it looks like with the silence left in it at that speed. Edited June 17, 2020 by ripdad czardas 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
JockoDundee Posted January 9, 2021 Share Posted January 9, 2021 On 6/17/2020 at 7:07 AM, ripdad said: There's an old saying: "there a hole in everything" -- And I found the hole that I was running into by accident. Do you think music has holes in it? Well, not literal holes -- rather silence. In other words, zero volume. And It does. More than most people know. I’m not sure I’ve heard that “old saying”. And I’m old; just saying There is however another old saying, “what goes up, must come down.” And so it is with sound; sound waves rise and fall in amplitude, many tens/hundreds or thousands of times a second. As they do they inevitably pass thru 0 db sound pressure, or zero-crossing. As for digital sound, it’s true that due to quantization that zero-crossings can be lengthened, depending on the sampling resolution. However, this effect is typically seen (heard) at very quiet parts, like the very tail of a fade-out. Moreover, any production recording includes dithering - random permutations of low-level noise specifically to prevent such artifacts. So I’m not sure what you are trying to accomplish when you say: On 6/17/2020 at 7:07 AM, ripdad said: Every musical note with its time duration. And the detail is astounding. Are you speaking only of the waveform graphic, or its audio or? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JockoDundee Posted July 30, 2021 Share Posted July 30, 2021 On 6/16/2020 at 3:01 PM, ripdad said: I have been playing with it some more and found that this is sufficient enough for me. For $i = 1 To 2 Next Just don’t run it on a different computer, or with a different load… Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
water Posted July 30, 2021 Share Posted July 30, 2021 4 hours ago, SameFraz said: a very good article everyone can lis If you like a post or a thread simply click on the heart icon in the lower right corner So the OP can easily see how many people like his work. 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