Browse Source

* TFPList benchmark old vs. generic

git-svn-id: trunk@5684 -
florian 18 years ago
parent
commit
d105f287c7
3 changed files with 74 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 29 0
      tests/bench/blists1.inc
  3. 43 0
      tests/bench/blists1.pp

+ 2 - 0
.gitattributes

@@ -5459,6 +5459,8 @@ tests/MPWMake -text
 tests/Makefile svneol=native#text/plain
 tests/Makefile.fpc svneol=native#text/plain
 tests/bench/ansibench.pp -text
+tests/bench/blists1.inc svneol=native#text/plain
+tests/bench/blists1.pp svneol=native#text/plain
 tests/bench/dmisc.pas svneol=native#text/plain
 tests/bench/drystone.pas svneol=native#text/plain
 tests/bench/pi.c -text

+ 29 - 0
tests/bench/blists1.inc

@@ -0,0 +1,29 @@
+  L:=TFPList.Create;
+  Try
+    T1:=Now;
+    L.Capacity:=Max;
+    For I:=0 to Max-1 do
+      L.Add(Pointer(I));
+    L.Clear;
+    For I:=0 to Max-1 do
+      L.Add(Pointer(I));
+    // Hustle
+    For I:=0 to Max-1 do
+      begin
+      J:=Random(Max);
+      K:=Random(Max);
+      L.Exchange(J,K);
+      end;
+    // Simple search
+    For I:=0 to Max-1 do
+      begin
+      J:=L.IndexOf(Pointer(I));
+      end;
+    // Simple search and remove
+    For I:=Max-1 downto 0 do
+      L.Remove(Pointer(I));
+    T2:=Now;
+    Writeln('Time : ',FormatDateTime('hh:nn:ss.zzz',T2-T1));
+  Finally
+    L.Free;
+  end;

+ 43 - 0
tests/bench/blists1.pp

@@ -0,0 +1,43 @@
+{$mode objfpc}
+{$h+}
+program testl;
+
+uses
+     fgl,
+     classes,
+     sysutils;
+
+Const
+  Max = 20000;
+
+
+procedure do_normal;
+Var
+  L : TFPList;
+  I : Ptrint;
+  J,K : Integer;
+  T1,T2 : TDateTime;
+begin
+  Writeln('Using old classes pointer list');
+  {$i blists1.inc}
+end;
+
+{ overwrite with generic one }
+Type
+   TFPList = specialize TFPGList<Pointer>;
+procedure do_generic;
+Var
+  L : TFPList;
+  I : Ptrint;
+  J,K : Integer;
+  T1,T2 : TDateTime;
+begin
+  Writeln('Using generics based pointer list');
+  {$i blists1.inc}
+end;
+
+
+begin
+  do_generic;
+  do_normal;
+end.