Wednesday, 15 January 2014

Delphi - How to make timer in milliseconds or nanoseconds with start/stop functions? -



Delphi - How to make timer in milliseconds or nanoseconds with start/stop functions? -

i looking timer in milliseconds or nanoseconds in delphi7. have check speeds of 3 isam files sequential search. first ind file contains 50 strings "record_0" "record_50". sec - "record_0" "record_500" , 3rd - "record_0" "record_5000". i've implemented don't know how create timer. comparing string lastly item in each isam file. here code first ind file:

procedure tform1.button1click(sender: tobject); var i:integer; var content : string[20]; var indexcounter:integer; var keyword:string; begin //first isam file assignfile(indf1, 'index1.ind'); rewrite(indf1); reset(indf1); i:=0 49 begin content := 'record_'; content := content + inttostr(i+1); index1.index1 := content; index1.position1 := filesize(indf1); seek(indf1, filesize(indf1)); write(indf1, index1); end; closefile(indf1); label12.caption := filesizestr('index1.ind'); //sequential search in first ind file reset(indf1); keyword := 'record_50'; indexcounter := 0; //start timer while not eof(indf1) begin seek(indf1, indexcounter); read(indf1, index1); if (keyword = index1.index1) begin //stop timer; //label20 := milliseconds/nanoseconds; //return/break while loop (result := -1; exit;) ??? end; indexcounter := indexcounter + 1; end;

i need procedure/function when phone call it should start counting in milliseconds or nanoseconds , stop when string found (it's lastly string in each ind file) , show elapsed time traversing through file. don't know how break while loop. in advance.

the tstopwatch class described here "delphi-high-performance-timer-tstopwatch" has functions needed (for delphi-7).

it's implemented in later delphi versions (delphi-2010) advanced record in unit diagnostics.

example:

var sw : tstopwatch; elapsedmilliseconds : cardinal; begin ... sw := tstopwatch.create() ; seek sw.start; while not eof(indf1) begin seek(indf1, indexcounter); read(indf1, index1); if (keyword = index1.index1) begin sw.stop; label20.caption := inttostr(sw.elapsedmilliseconds); break; // break while loop end; indexcounter := indexcounter + 1; end; ... sw.free; end; end;

to break while loop, break; within conditional test.

delphi timer while-loop milliseconds

No comments:

Post a Comment