Created
October 28, 2021 09:32
-
-
Save xavierlopezpujol/8955c564ed14475e54272f83d1cfa05b to your computer and use it in GitHub Desktop.
Metrics TObjectList, TList, Array of records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program MedicionesArrayTObjectList; | |
{$APPTYPE CONSOLE} | |
{$R *.res} | |
uses | |
System.SysUtils, | |
System.Generics.Collections, | |
Syncommons; | |
type | |
Tpuntof3D = record | |
x:extended; | |
y:extended; | |
z:extended; | |
end; | |
TParticle = record | |
p: Tpuntof3D; | |
inputFace:integer; | |
end; | |
TCParticle = Class | |
private | |
inputFace:integer; | |
p: Tpuntof3D; | |
public | |
End; | |
TListaObjectos = TObjectList<TCParticle>; | |
TRecordsList = TList<TParticle>; | |
function MemoryUsed: UInt64; | |
var | |
st: TMemoryManagerState; | |
sb: TSmallBlockTypeState; | |
begin | |
GetMemoryManagerState(st); | |
result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize; | |
for sb in st.SmallBlockTypeStates do begin | |
result := result + sb.UseableBlockSize * sb.AllocatedBlockCount; | |
end; | |
end; | |
// | |
var | |
MemoriaInicialMain : UInt64; | |
T : TPrecisionTimer; | |
// | |
procedure ArrayOfRecord; | |
var i : integer; | |
ListaA : array of Tparticle ; | |
MemoriaInicial : UInt64; | |
t : TPrecisiontimer; | |
begin | |
MemoriaInicial := MemoryUsed; | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
t.Start; | |
Setlength (ListaA,10000000); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
for i := 0 to 9999999 do | |
begin | |
ListaA[i].inputFace := i; | |
end; | |
writeln(formatUTF8('T creacion+insercion=%',[t.Stop])); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
Setlength (ListaA,0); | |
end; | |
// | |
procedure TObjectListOfObject; | |
var i : integer; | |
CParticle : TCParticle; | |
OL : TListaObjectos; | |
MemoriaInicial : UInt64; | |
t : TPrecisiontimer; | |
begin | |
MemoriaInicial := MemoryUsed; | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
t.Start; | |
OL := TListaObjectos.Create(); | |
try | |
for i := 0 to 9999999 do | |
begin | |
CParticle := TCParticle.create; | |
CParticle.inputFace := i; | |
OL.Add(CParticle); | |
end; | |
writeln(formatUTF8('T creacion+insercion=%',[t.Stop])); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
finally | |
OL.Free; | |
end; | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
end; | |
procedure TListOfRecord; | |
var i : integer; | |
RecordsList : TRecordsList; | |
MemoriaInicial : UInt64; | |
Particle : TParticle; | |
t : TPrecisiontimer; | |
begin | |
MemoriaInicial := MemoryUsed; | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
t.Start; | |
RecordsList := TRecordsList.Create; | |
try | |
for i := 0 to 9999999 do | |
begin | |
Particle.inputFace := i; | |
RecordsList.Add(Particle); | |
end; | |
writeln(formatUTF8('T creacion+insercion=%',[t.Stop])); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
finally | |
RecordsList.Free; | |
end; | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicial)])); | |
end; | |
// MAIN | |
begin | |
ReportMemoryLeaksOnShutdown := true; | |
MemoriaInicialMain := MemoryUsed; | |
// | |
writeln; | |
writeln('TObjectListOfObject'); | |
t.start; | |
TObjectListOfObject; | |
writeln(formatUTF8('T=%',[t.Stop])); | |
writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicialMain)])); | |
writeln; | |
writeln('TListOfRecord'); | |
t.start; | |
TListOfRecord; | |
writeln(formatUTF8('T=%',[t.Stop])); | |
writeln; | |
writeln('ArrayOfRecord'); | |
t.start; | |
ArrayOfRecord; | |
writeln(formatUTF8('T=%',[t.Stop])); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicialMain)])); | |
Writeln('MEMORIA USADA='+format('%d',[(MemoryUsed - MemoriaInicialMain)])); | |
readln; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment