Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.

Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:

 Run N seconds worth of jobs and/or Y jobs.
 Report at least three distinct times.

Be aware of the precision and accuracy limitations of your timing mechanisms, and document them if you can.

See also: System time, Time a function

 
program Rate_counter;
 
{$APPTYPE CONSOLE}
 
uses
  System.SysUtils,
  System.Diagnostics;
 
var
  a: Integer;
 
function TickToString(Tick: Int64): string;
var
  ns, us, ms, s, t: Cardinal;
begin
  Result := '';
  ns := (Tick mod 10) * 100;
  if ns > 0 then
    Result := format(' %dns', [ns]);
 
  t := Tick div 10;
  us := t mod 1000;
  if us > 0 then
    Result := format(' %dus', [us]) + Result;
 
  t := t div 1000;
  ms := t mod 1000;
  if ms > 0 then
    Result := format(' %dms', [ms]) + Result;
 
  t := t div 1000;
  s := t mod 1000;
  if s > 0 then
    Result := format(' %ds', [s]) + Result;
end;
 
function Benchmark(Fns: TArray<TProc>; times: Cardinal): TArray<string>;
var
  Stopwatch: TStopwatch;
  fn: TProc;
  i, j: Cardinal;
begin
  SetLength(result, length(Fns));
  Stopwatch := TStopwatch.Create;
 
  for i := 0 to High(Fns) do
  begin
    fn := Fns[i];
    if not Assigned(fn) then
      Continue;
    Stopwatch.Reset;
    Stopwatch.Start;
    for j := 1 to times do
      fn();
    Stopwatch.Stop;
    Result[i] := TickToString(Stopwatch.ElapsedTicks);
  end;
end;
 
procedure F0();
begin
end;
 
procedure F1();
begin
  var b := a;
end;
 
procedure F2();
begin
  var b := a.ToString;
end;
 
begin
  writeln('Time fx took to run 10,000 times:'#10);
  var r := Benchmark([F0, F1, F2], 10000);
  for var i := 0 to High(r) do
    writeln('f', i, ': ', r[i]);
  Readln;
end.