); assert( count=length(funcnames) ); memo1.lines.add( format('substr index: %d; loop count = %d', [istr, loopcount]) ); setlength( retv, count ); setlength( results, count ); for j:=0 to count-1 do results[j] := 0; for k:=1 to test_count do begin for j:=0 to count-1 do begin func := funcs[j]; tm := gettickcount; for i:=1 to loopcount do retv[j] := func( istr, substr, str ); inc( results[j], gettickcount - tm ); end; end; for j:=0 to count-1 do begin memo1.lines.add( format( '%s: return %d; timing: %n ms', [funcnames[j], retv[j], results[j]*1.0/test_count ] ) ); end; end; procedure tform1.button1click(sender: tobject); var i: integer; begin for i:=1 to 4 do begin memo1.lines.add( format( '%d:', [i]) ); tests( [@getnsubstringpos], ['getnsubstringpos'], i, 1000 ); tests( [@posn_pos, @posn_posex, @posn_strpos], ['posn_pos', 'posn_posex', 'posn_strpos'], i, 100000 ); end; end; procedure tform1.formcreate(sender: tobject); begin memo1.clear; memo1.lines.add( format( 'search "%s" for "%s"', [str, substr] ) ); end; end.
unit1.dfm: