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

Procedure.d TimesPSec(Reset=#False)
  Static starttime, cnt
  Protected Result.d, dt
  If Reset
    starttime=ElapsedMilliseconds(): cnt=0
  Else
    cnt+1
    dt=(ElapsedMilliseconds()-starttime)
    If dt
      Result=cnt/(ElapsedMilliseconds()-starttime)
    EndIf
  EndIf
  ProcedureReturn Result*1000
EndProcedure
 
If OpenWindow(0,#PB_Ignore,#PB_Ignore,220,110,"",#PB_Window_SystemMenu)
  Define Event, r.d, GadgetNumber
  ButtonGadget(0,10, 5,200,35,"Click me!")
  ButtonGadget(1,10,70,100,35,"Reset")
  TextGadget  (2,10,45,200,25,"")
  TimesPSec(1)
  Repeat
    Event=WaitWindowEvent()
    If Event=#PB_Event_Gadget 
      GadgetNumber =EventGadget()
      If GadgetNumber=0
        r=TimesPSec()
        SetGadgetText(2,"You are clicking at "+StrD(r,5)+" Hz.")
      ElseIf GadgetNumber=1
        TimesPSec(1)
        SetGadgetText(2,"Counter zeroed.")
      EndIf
    EndIf
  Until Event=#PB_Event_CloseWindow
EndIf