Einzelnen Beitrag anzeigen

EgonHugeist

Registriert seit: 17. Sep 2011
187 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#94

AW: Anzahl eines Zeichens im String ermitteln

  Alt 13. Jul 2018, 17:32
Zum Spaß:
Delphi-Quellcode:
function EH_CharCount_4(const S: string; C: Char): Cardinal;
var
  P, PEnd: PChar;
begin
  Result := 0;
  P := Pointer(S);
  if P = nil then Exit;
  PEnd := P + PStrLenInt(NativeUInt(P) - SizeOf(StrLenInt))^-1;
  if PEnd = p //handle single char string
  then Inc(Result, Ord(P^ = C))
  else while P < PEnd do begin
    Inc(Result, Ord(P^ = C));
    Inc(P);
    if PEnd >= P then begin
      Inc(Result, Ord(PEnd^ = C));
      Dec(PEnd);
    end;
  end;
end;
Results mit Uwes test:
(Run 1)
Zitat:
Starting Benchmark, please be patient...
KodeZwerg's custom Benchmark - DP CountCharInString Edition
Result := 7982

Calibrate - Target missed: 0 <> 7982
00000 Calibrate
04905 1234588 miep
08639 Ydobon
04217 marabu
05136 Missionar
04639 alzaimar
04337 Uwe Raabe StringCountChar
04164 Uwe Raabe StringCountCharFor
04061 KodeZwerg CountCharInString
10075 KodeZwerg CharInStringA
04451 Neutral General CharCountAsm
04301 Uwe Raabe CharCount
03949 Egon Hugeist CharCount_1
04398 Egon Hugeist CharCount_2
04485 Egon Hugeist CharCount_Double_Sided
03702 Egon Hugeist CharCount_Double_Sided_2
04578 Delphi CountChar
Benchmark finished!
(Run 2)
Zitat:
Starting Benchmark, please be patient...
KodeZwerg's custom Benchmark - DP CountCharInString Edition
Result := 7982

Calibrate - Target missed: 0 <> 7982
00000 Calibrate
04865 1234588 miep
07914 Ydobon
04114 marabu
05044 Missionar
04479 alzaimar
04317 Uwe Raabe StringCountChar
04125 Uwe Raabe StringCountCharFor
04158 KodeZwerg CountCharInString
10157 KodeZwerg CharInStringA
04583 Neutral General CharCountAsm
04390 Uwe Raabe CharCount
03953 Egon Hugeist CharCount_1
04431 Egon Hugeist CharCount_2
04505 Egon Hugeist CharCount_Double_Sided
03740 Egon Hugeist CharCount_Double_Sided_2
04597 Delphi CountChar
Benchmark finished!
  Mit Zitat antworten Zitat