Einzelnen Beitrag anzeigen

Der schöne Günther
Online

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#5

AW: PosEx? Oder doch lieber Pos? - Performance!

  Alt 22. Aug 2016, 18:18
Also eine Millionen mal dauert Posex bei mir 6 Millisekunden und 7 Millisekunden für "Pos".

Delphi-Quellcode:
program Project11;

{$APPTYPE CONSOLE}

{$R *.res}

uses System.SysUtils, System.AnsiStrings, System.Diagnostics;

const
 s1 = 'Hallo Welt';
 s2 = 'lo';

 count = 1E6;

//{$Define Posex}

var
   times: Integer;
   result: Integer;
   stopWatch: TStopwatch;
begin
   times := 0;
   stopWatch := TStopwatch.StartNew();
   repeat
      {$If Defined(Posex)}
         result := System.AnsiStrings.PosEx(s2, s1);
      {$Else}
         result := System.Pos(s2, s1);
      {$EndIf}
      Inc(times);
   until (times = count);
   stopWatch.Stop();

   Writeln( stopWatch.ElapsedMilliseconds );
   readln;
end.

Wenn du in die Implementation schaust wirst du sehen dass PosEx nichts anderes tut als Pos aufzurufen. PosEx hat aber noch eine "inline"-Direktive. Ich kann kein Assembler lesen, könnte mir aber vorstellen dass der Compiler dann das komplette "Pos" inlined sodass er sich einen Sprung spart. Könnte das mal jemand prüfen?
  Mit Zitat antworten Zitat