Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, Hi all,
I want to make a loop function, and I want it to be as fast as possible, so the wait time (XX value) at the end is the less value possible
Function Main
rep
,_i=MyFunction
,if(_i=2)
,,DoSomething
,,goto 22
,Wait XX
;22
So, is it possible to know the average time spent by MyFunction to execute, so the XX value is the less possible?
I'd like a way to make average time for, say, 50 execution to calculate XX value as the most accurate possible value.
Thanks
Posts: 12,097
Threads: 142
Joined: Dec 2002
To measure code execution time I use PerfX functions.
Two examples.
Macro Macro471
;simple
PerfFirst
0.01
PerfNext
PerfOut
;part of loop
PerfOut 1
rep 10
,0.01 ;;don't measure this
,PerfFirst
,0.005 ;;measure only this
,PerfNext
,PerfOut 2
,0.01 ;;don't measure this
PerfOut 3 ;;show sum (0.005 s * 10)
When need the time value in the macro, use perf. When don't need microsecond precision, use GetTickCout or timeGetTime.
Macro Macro272
long t1=perf
0.01
long t2=perf
out t2-t1
int t3=timeGetTime
0.02
int t4=timeGetTime
out t4-t3
Posts: 795
Threads: 136
Joined: Feb 2009
TY, as usual...
three methods show average time between 350 and 510 microseconds.
What is the best value then for XX for the wait value in the loop?
rep
,_i=MyFunction
,if(_i=2)
,,DoSomething
,,goto 22
,Wait XX <<<<<<<< this one
Posts: 12,097
Threads: 142
Joined: Dec 2002
If I understand correctly, I would look in Task Manager how much CPU it consumes...
Posts: 795
Threads: 136
Joined: Feb 2009
very low, in fact....
i just need to know if wait 0.01 if the lowest wait time QM can handle, documentation says 2 ms is the treshold, so if I understand correctly, it's the minimum accurate
wait value available, or can I put 1 ms safely????
From QM help
"The wait time precision is about 2 milliseconds (0.002 s). For example, wait 0.001 will probably wait 2 ms."
Correct????
Posts: 12,097
Threads: 142
Joined: Dec 2002
Yes, 2 ms.
wait 0.001 would wait 2 ms.
wait 0.003 - 4 ms.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, it's 4 times the function execution time, so fits the bill.
i'll use wait 0.001 in my functions when needed the lesser wait time.
Now I have another question:
i need to monitor and make vissible on my computer those values calcualted each 2 ms.
As it's very short time between two values, OnScreenDisplay is no more usable.
Can you give me a hint about a valuable method to show those 2 ms values change (must be visible all the time)....
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro Macro274
int n tOSD=timeGetTime; long tSum
rep
,long t1=perf
,sub.Func
,long t2=perf
,
,n+1; tSum+(t2-t1)
,int tNow=timeGetTime
,if tNow-tOSD>=100 ;;update OSD every 100 ms
,,OnScreenDisplay F"{tSum/n}" -1 0 0 "" 0 0 4|8 "time" ;;show average sub.Func time during the last 100 ms
,,tSum=0; n=0; tOSD=tNow
,
,0.001
#sub Func
;this function consumes CPU 100 to 1000 microseconds
long t0(perf) time=RandomInt(100 1000)
rep
,if(perf-t0>=time) break
Posts: 795
Threads: 136
Joined: Feb 2009
you're a god, TY so much....
Posts: 795
Threads: 136
Joined: Feb 2009
just to to know, is the 100 ms a random value or the best/lower accurate value to be used in QM or with OSD function?
wait 0.001 does not allow to output a value in output panel in Qm...
Posts: 12,097
Threads: 142
Joined: Dec 2002
I used 100 ms because human eyes and mind normally cannot process more frequent view updating. Probably it is too fast. Values between 300 and 1000 should be the best.
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 795
Threads: 136
Joined: Feb 2009
Reviving this,
is it possible to reproduce the osd output with same text and same interval in a tray icon, or too complicated????
Posts: 12,097
Threads: 142
Joined: Dec 2002
Posts: 795
Threads: 136
Joined: Feb 2009
|