扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
function Pos(Substr: string; S: string): Integer; |
function RightPos(const Substr,S: string): Integer; var iPos: Integer; TmpStr:string; begin TmpStr:=s; iPos := Pos(Substr,TmpStr); Result:=0; //查找Substr第一次出现位置 while iPos<>0 do begin Delete(TmpStr,1,iPos+length(Substr)-1); //删除已经查找过的字符 Result:=Result+iPos; iPos := Pos(Substr,TmpStr); //查找Substr出现位置 if iPos=0 then break; Result:=Result+length(Substr)-1; end; end; |
procedure _LStrDelete{ var s : AnsiString; index, count : Integer }; asm { EAX Pointer to s } { EDX index } { ECX count } PUSH EBX PUSH ESI PUSH EDI MOV EBX,EAX MOV ESI,EDX MOV EDI,ECX CALL UniqueString MOV EDX,[EBX] TEST EDX,EDX { source already empty: nothing to do } JE @@exit MOV ECX,[EDX-skew].StrRec.length { make index 0-based, if not in [0 .. Length(s)-1] do nothing } DEC ESI JL @@exit CMP ESI,ECX JGE @@exit { limit count to [0 .. Length(s) - index] } TEST EDI,EDI JLE @@exit SUB ECX,ESI { ECX = Length(s) - index } CMP EDI,ECX JLE @@1 MOV EDI,ECX @@1: { move length - index - count characters from s+index+count to s+index } SUB ECX,EDI { ECX = Length(s) - index - count } ADD EDX,ESI { EDX = s+index } LEA EAX,[EDX+EDI] { EAX = s+index+count } CALL Move { set length(s) to length(s) - count } MOV EDX,[EBX] MOV EAX,EBX MOV EDX,[EDX-skew].StrRec.length SUB EDX,EDI CALL _LStrSetLength @@exit: POP EDI POP ESI POP EBX end; |
function RightPosEx(const Substr,S: string): Integer; var iPos: Integer; TmpStr:string; i,j,len: Integer; PCharS,PCharSub:PChar; begin PCharS:=PChar(s); //将字符串转化为PChar格式 PCharSub:=PChar(Substr); Result:=0; len:=length(Substr); for i:=0 to length(S)-1 do begin for j:=0 to len-1 do begin if PCharS[i+j]<>PCharSub[j] then break; end; if j=len then Result:=i+1; end; |
var i,len,iPos: Integer; PerformanceCount1,PerformanceCount2,Count:int64; begin len:=10000; //重复次数 QueryPerformanceCounter(PerformanceCount1);//开始计数 for i:=0 to len-1 do begin iPos:=RightPos(’12’,Edit1.Text); //被测试的函数 end; QueryPerformanceCounter(PerformanceCount2); //结束计数 Count:=(PerformanceCount2-PerformanceCount1); Label1.Caption:=inttostr(iPos)+’ time=’+inttostr(Count); End; |
函数名 | 重复次数 | QueryPerformanceCounter 计数值 |
Pos | 10000 | 150000 |
RightPos | 10000 | 217000 |
RightPosEx | 10000 | 160000 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者