Delphi实验:在串中查找第i个子串的位置及效率评测[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 agui 的 blog

); 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:

本文关键:Delphi实验:在串中查找第i个子串的位置及效率评测
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top