mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 00:09:23 +02:00
* TFPList benchmark old vs. generic
git-svn-id: trunk@5684 -
This commit is contained in:
parent
a166a31b61
commit
d105f287c7
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -5459,6 +5459,8 @@ tests/MPWMake -text
|
|||||||
tests/Makefile svneol=native#text/plain
|
tests/Makefile svneol=native#text/plain
|
||||||
tests/Makefile.fpc svneol=native#text/plain
|
tests/Makefile.fpc svneol=native#text/plain
|
||||||
tests/bench/ansibench.pp -text
|
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/dmisc.pas svneol=native#text/plain
|
||||||
tests/bench/drystone.pas svneol=native#text/plain
|
tests/bench/drystone.pas svneol=native#text/plain
|
||||||
tests/bench/pi.c -text
|
tests/bench/pi.c -text
|
||||||
|
29
tests/bench/blists1.inc
Normal file
29
tests/bench/blists1.inc
Normal file
@ -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
tests/bench/blists1.pp
Normal file
43
tests/bench/blists1.pp
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user