Measuring speed with high precision

Functions, classes, components, etc. Only high quality content.

Measuring speed with high precision

Postby Gintaras on Sun Jan 09, 2005 8:55 am

This method allows to see how long one or several commands run, with precision of 1 microsecond (0.000001 s).


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

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

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

double d; long l

if(!QueryPerformanceFrequency(&l)) ret

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

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

Q &q ;;take time 1
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.

How to measure several times?

You can measure up to 4 times.

Q &q
Q &qq
Q &qqq
Q &qqqq
Q &qqqqq

Site Admin
Posts: 10369
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Return to QM Extensions

Who is online

Users browsing this forum: No registered users and 3 guests