Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Measuring speed with high precision
#1
This method allows to see how long one or several commands run, with precision of 1 microsecond (0.000001 s).

Setup

Place the following 2 lines in the init2 function. If function init2 does not exist, create it, place this code and run.

Code:
Copy      Help
long+ q qq qqq qqqq qqqqq
dll "kernel32" [QueryPerformanceCounter]#Q long*pc

Create new function, name it outq. Here is the code:

Code:
Copy      Help
double d; long l

if(!QueryPerformanceFrequency(&l)) ret
d=1000000.0/l

int i(qq-q*d) ii(qqq-qq*d) iii(qqqq-qqq*d) iiii(qqqqq-qqqq*d)
out "%i %i %i %i" i ii iii iiii
ret i


How to use

Example1
How much time runs code that consists of two lines line1 and line2?

Code:
Copy      Help
Q &q ;;take time 1
line1
line2
Q &qq ;;take time 2
outq ;;output time difference between time 1 and time 2

In Output you will see 4 numbers. In this example, valid is only the first. It is number of microseconds between Q &q and Q &qq.

Example2
How to measure several times?

You can measure up to 4 times.

Code:
Copy      Help
Q &q
...
Q &qq
...
Q &qqq
...
Q &qqqq
...
Q &qqqqq
outq


Forum Jump:


Users browsing this thread: 1 Guest(s)