Measuring speed with high precision Gintaras Administrator Posts: 10,942 Threads: 125 Joined: Dec 2002 01-09-2005, 08:55 AM 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: ```long+ q qq qqq qqqq qqqqq dll "kernel32" [QueryPerformanceCounter]#Q long*pc``` Create new function, name it outq. Here is the code: Code: ```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: ```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: ```Q &q ... Q &qq ... Q &qqq ... Q &qqqq ... Q &qqqqq outq``` Reply Reply « Next Oldest | Next Newest »