Microsoft Small Basic

Program Listing: RZJ560
' Profiler Sample
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Last update 2015-06-30
'
color = "1=Gray;2=Cyan;3=Blue;"
ic = 1
Profiler_Init() ' for profile
For i = 1 To 20
For j = 1 To 79
InnerLoop()
EndFor
OuterLoop()
EndFor
TextWindow.ForegroundColor = "Gray"
Profiler_Dump() ' for profile

Sub OuterLoop
subName = "OuterLoop" ' for profile
Profiler_Begin() ' for profile
TextWindow.WriteLine("")
Program.Delay(20)
ic = ic + 1
If 3 < ic Then
ic = 1
EndIf
TextWindow.ForegroundColor = color[ic]
Profiler_End() ' for profile
EndSub

Sub InnerLoop
subName = "InnerLoop" ' for profile
Profiler_Begin() ' for profile
TextWindow.Write(".")
Program.Delay(20)
Profiler_End() ' for profile
EndSub

Sub Profiler_Init ' for profile
Timer.Interval = 50
Timer.Tick = Profiler_OnTick
Profiler_sub = "main"
EndSub

Sub Profiler_OnTick ' for profile
profile[Profiler_sub] = profile[Profiler_sub] + 1
EndSub

Sub Profiler_Begin ' for profile
Stack.PushValue("local", Profiler_sub)
Profiler_sub = subName
EndSub

Sub Profiler_End ' for profile
Profiler_sub = Stack.PopValue("local")
EndSub

Sub Profiler_Dump ' for profile
nProfile = Array.GetItemCount(profile)
index = Array.GetAllIndices(profile)
For iProfile = 1 To nProfile
TextWindow.WriteLine(index[iProfile] + " : " + profile[index[iProfile]])
EndFor
TextWindow.WriteLine("")
EndSub