Use the unit SysUtils and from that the Now() function - it will give you the current date and time. Call it once before and once after whatever you want to measure. Since TDateTime is in fact only a Double you can operate arithmetically on it (subtraction) - that way you can later just pull each time (and date) component to see how long it lasted:
program TimeDiff;
uses
SysUtils; // Every Pascal implementation should have this
// Just pointless calculations to waste CPU cycles
function RoutineToMeasure(): Integer;
var
i, j: Integer;
begin
result:= 0;
for i:= 0 to $7FFFFFFF do begin
j:= i div 24;
j:= j+ 10;
result:= result xor j;
result:= result or i;
end;
end;
// The actual program to measure times
var
tStart, tEnd, tDiff: TDateTime; // Begin and end of measurement, and difference
iHours, iMinutes, iSeconds, iMilliseconds: Word; // Time components
begin
tStart:= Now(); // Get date+time
RoutineToMeasure();
tEnd:= Now(); // Get date+time again
// To be read by a human
Writeln( ' started: ', DateTimeToStr( tStart ) );
Writeln( ' finished: ', DateTimeToStr( tEnd ) );
// Calculating the actual time it took
tDiff:= tEnd- tStart; // Subtract higher from lower value
DecodeTime( tDiff, iHours, iMinutes, iSeconds, iMilliseconds ); // Does not account for day changes when executing around midnight
Writeln( ' taken: ', iHours, ' h, ', iMinutes, ' min, ', iSeconds, ' sec, ', iMilliseconds, ' msec' );
Readln();
end.
Successfully tested in Lazarus 2.2.0 with FCP 3.2.2; the output is as per a 4 core 3.2 GHz CPU:
started: 2022-12-14 14:33:07
finished: 2022-12-14 14:33:12
taken: 0 h, 0 min, 5 sec, 323 msec
time. Did you mean you want to measure the time a subroutine takes?