Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Macro execution time
#1
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
Code:
Copy      Help
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
#2
To measure code execution time I use PerfX functions.

Two examples.
Macro Macro471
Code:
Copy      Help
;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
Code:
Copy      Help
long t1=perf
0.01
long t2=perf
out t2-t1

int t3=timeGetTime
0.02
int t4=timeGetTime
out t4-t3
#3
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
#4
If I understand correctly, I would look in Task Manager how much CPU it consumes...
#5
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????
#6
Yes, 2 ms.
wait 0.001 would wait 2 ms.
wait 0.003 - 4 ms.
#7
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)....
#8
Macro Macro274
Code:
Copy      Help
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
#9
you're a god, TY so much....
#10
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...
#11
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.
#12
Perfect, thanks.
#13
Reviving this,

is it possible to reproduce the osd output with same text and same interval in a tray icon, or too complicated????
#14
similar
Icon ShowProgress
#15
ty


Forum Jump:


Users browsing this thread: 1 Guest(s)