Repository navigation
Expand file tree
/
Copy pathloadtest3.lpr
More file actions
74 lines (60 loc) · 1.67 KB
/
Copy pathloadtest3.lpr
File metadata and controls
74 lines (60 loc) · 1.67 KB
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
program loadtest3;
uses classes, sysutils, streamex;
procedure ProcessLine(const S: string);
//var
//fields: array of string;
begin
//fields := s.Split([','], '"', '"');
//if fields[4] = 'Australia' then
if Pos('Australia', S) > 0 then
Writeln(S);
end;
const
g_Organisations = 'organizations-500000.csv';
procedure Main;
var
FS: TFileStream;
SR: TStreamReader;
Line: string;
HS: THeapStatus;
begin
FS := TFileStream.Create(g_Organisations, fmOpenRead or fmShareDenyNone);
SR := TStreamReader.Create(FS);
try
while not SR.EndOfStream do
begin
Line := SR.ReadLine;
ProcessLine(Line);
end;
HS := GetHeapStatus;
Writeln('Total allocated (bytes): ', HS.TotalAllocated);
Writeln('Total free (bytes): ', HS.TotalFree);
finally
SR.Free;
FS.Free;
end;
end;
var
StartTime, EndTime: QWord;
ElapsedMs, ElapsedSec: Double;
CPU_TDP_Watts: Double;
Energy_Joules, Energy_Ws, Energy_kWh: Double;
begin
// Set your CPU TDP (Watts)
CPU_TDP_Watts := 15.0;
StartTime := GetTickCount64;
Main;
EndTime := GetTickCount64;
// Calculate elapsed time
ElapsedMs := EndTime - StartTime;
ElapsedSec := ElapsedMs / 1000.0;
// Calculate energy usage
Energy_Joules := CPU_TDP_Watts * ElapsedSec;
Energy_Ws := Energy_Joules; // 1 Joule = 1 Watt-second
Energy_kWh := Energy_Joules / 3600000.0; // 1 kWh = 3,600,000 J
// Output results
Writeln(Format('Elapsed Time: %.3f ms (%.5f s)', [ElapsedMs, ElapsedSec]));
Writeln(Format('Estimated Energy: %.5f J', [Energy_Joules]));
Writeln(Format('Estimated Energy: %.5f Ws', [Energy_Ws]));
Writeln(Format('Estimated Energy: %.10f kWh', [Energy_kWh]));
end.