For programmers, it is very important to use a certain command and ask it to run according to the time given by the programmer, for example: a coder writes an auto game program and then when the code operations are complete and when he runs the test, it does not work as he wants (runs in a messy way and the timeout, the execution time is not in the right order) and forces the coder to do repeat the steps and estimate the time. So how do we accurately measure each time (milliseconds) that a command runs? Specifically Autoit
Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
AutoIT is not a powerful programming language, but it has proven itself to be a useful language right on the command line itself. Therefore, we need to measure and know how much time an instruction in a programming language takes and give a reasonable timeout.
I will guide in detail the code steps for you to understand easily:
The structure of the time measurement code is as follows:
Local $time = TimerInit() ; Lấy thời gian của hệ thống, tính bằng mili giây
; Các lệnh cần đo được chèn ở đây
Local $timedo = TimerDiff($time)
MsgBox(0, "Thời gian đo được", "Thời gian đo được là :" & @CRLF & $timedo)
Example 1: Measure the duration of the Sleep(5000) instruction
Code :
Local $time = TimerInit()
Sleep(5000)
Local $timedo = TimerDiff($time)
MsgBox(0, "Thời gian đo được", "Thời gian đo được là :" & @CRLF & $timedo)
Measured results:
Example 2: Measure the time to do the math
Code :
Local $time = TimerInit()
$x = 10
$y = 5
$z = $x + $y
Local $timedo = TimerDiff($time)
MsgBox(0, "Thời gian đo được", "Thời gian đo được là :" & @CRLF & $timedo)
MsgBox(0,0,$z)
Measured results:
Note: If you want to output the results after calculating, you must put Msgbox after the sample frame code to measure the time, if it is in the sample frame, it will also measure the time you click OK. In case you want to export the results before exporting the measured time, you must set Msgbox to output the results before Msgbox reports the measured time.
After successfully measuring an instruction, we can estimate the waiting time for the program most accurately. For example: You want to let the user wait for a certain command, but do not know how long it takes to wait, we can apply this code to measure first and use Sleep() in the most reasonable way 🙂
In addition to the above 2 code examples, you can completely measure other commands such as: measure the time to read a .txt file, measure the time to get the source code of a website, measure the time to create or delete a necessary file, …
Like Fanpage or in home page regularly to update good articles in the near future.
AnonyViet wishes you success !!
N1412