Snippets
Created by
Stefan Glienke
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | program Project1;
{$APPTYPE CONSOLE}
uses
Classes,
Diagnostics,
SysUtils,
Mitov.Attributes, Mitov.Types,
Spring;
type
TFoo = class
private
fCount: Integer;
fCount2: Integer;
fCount3: Integer;
fStrings: TStrings;
fIntf: IInterface;
public
constructor Create;
destructor Destroy; override;
property Count: Integer read fCount;
property Count2: Integer read fCount2;
property Count3: Integer read fCount3;
property Strings: TStrings read fStrings;
property Intf: IInterface read fIntf;
end;
TSpringFoo = class(TManagedObject)
private
[Default(42)]
fCount: Integer;
[Default(42)]
fCount2: Integer;
[Default(42)]
fCount3: Integer;
[Managed(TStringList)]
fStrings: TStrings;
[Managed(TInterfacedObject)]
fIntf: IInterface;
public
property Count: Integer read fCount;
property Count2: Integer read fCount2;
property Count3: Integer read fCount3;
property Strings: TStrings read fStrings;
property Intf: IInterface read fIntf;
end;
TMitovFoo = class(TBasicObject)
private
[Default(42)]
fCount: Integer;
[Default(42)]
fCount2: Integer;
[Default(42)]
fCount3: Integer;
[AutoManage(TStringList)]
fStrings: TStrings;
[AutoManage(TInterfacedObject)]
fIntf: IInterface;
public
property Count: Integer read fCount;
property Count2: Integer read fCount2;
property Count3: Integer read fCount3;
property Strings: TStrings read fStrings;
property Intf: IInterface read fIntf;
end;
{ TFoo }
constructor TFoo.Create;
begin
inherited Create;
fCount := 42;
fCount2 := 42;
fCount3 := 42;
fStrings := TStringList.Create;
fIntf := TInterfacedObject.Create;
end;
destructor TFoo.Destroy;
begin
fStrings.Free;
inherited;
end;
const
MAXCOUNT = 100000;
THREADCOUNT = 1;
procedure TestFoo;
var
i: Integer;
f: TFoo;
begin
for i := 1 to MAXCOUNT do
begin
f := TFoo.Create;
f.Free;
end;
end;
procedure TestSpring;
var
i: Integer;
f: TSpringFoo;
begin
for i := 1 to MAXCOUNT do
begin
f := TSpringFoo.Create;
f.Free;
end;
end;
procedure TestMitov;
var
i: Integer;
f: TMitovFoo;
begin
for i := 1 to MAXCOUNT do
begin
f := TMitovFoo.Create;
f.Free;
end;
end;
procedure Test(proc: TProcedure; const text: string);
var
sw: TStopwatch;
threads: array[1..THREADCOUNT] of TThread;
i: Integer;
begin
for i := 1 to THREADCOUNT do
begin
threads[i] := TThread.CreateAnonymousThread(proc);
threads[i].FreeOnTerminate := False;
end;
sw := TStopwatch.StartNew;
for i := 1 to THREADCOUNT do
threads[i].Start;
for i := 1 to THREADCOUNT do
begin
threads[i].WaitFor;
threads[i].Free;
end;
Writeln(text, ': ', sw.ElapsedMilliseconds, ' ms');
end;
begin
try
Writeln('testing creating and destroying ', MAXCOUNT, ' instances in ', THREADCOUNT, ' threads');
Writeln;
Test(TestFoo, 'native compiled');
Test(TestSpring, 'Spring4D');
Test(TestMitov, 'Mitov');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReportMemoryLeaksOnShutdown := True;
Readln;
end.
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.