logo WinWrap®
September 23, 2019

Profiling

Profiling (v10.41+):

  • Identify script execution bottlenecks
  • Line execution times
  • Procedure execution times

The sample script calculates prime numbers using two different algorithms. CalcPrimeSimple checks each number for primeness, while CalcPrimeSieve uses the Sieve of Eratosthenes to more quickly calculate all prime numbers in the range.

The '#Profile special comment stores the execution times for the script when the script completes.

'#Language "WWB-COM" '#Profile MacroDir & "primes-profile.txt" Option Explicit Const limit1 As Long = 10000 Dim composite1(limit1) As Boolean Const limit2 As Long = 100000 Dim composite2(limit2) As Boolean Sub Main CalcPrimeSimple CalcPrimeSieve Verify 'Save End Sub Sub CalcPrimeSimple ' test each number individually Dim i As Long, j As Long For i = 2 To limit1 Dim composite As Boolean composite = False For j = 2 To Sqr(i) If i Mod j = 0 Then composite = True Exit For End If Next composite1(i) = composite Next End Sub Sub CalcPrimeSieve ' sieve of Eratosthenes Dim i As Long, j As Long For i = 2 To Sqr(limit2) If Not composite2(i) Then For j = 2*i To limit2 Step i composite2(j) = True Next End If Next End Sub Sub Verify Dim i As Integer For i = 2 To limit1 If composite1(i) <> composite2(i) Then Stop Next End Sub Sub Save Open MacroDir & "\primes-simple.txt" For Output As #1 Dim i As Long For i = 2 To limit1 If Not composite1(i) Then Print #1, i Next Close #1 Open MacroDir & "\primes-sieve.txt" For Output As #1 For i = 2 To limit2 If Not composite2(i) Then Print #1, i Next Close #1 End Sub

Profile

Procedure execution times (total-seconds) for CalcPrimesSimple and CalcPrimesSieve are similar. However, CalcPrimesSieve calculates 10 times as many primes as CalcPrimesSimple does in the same amount of time.

firstlasthitsdirect-secondstotal-secondsname
0000.0000000.000000*HiddenLines*
121710.0098750.109202Main
193310.0490340.049034CalcPrimeSimple
354510.0450480.045048CalcPrimeSieve
475210.0052440.005244Verify
546700.0000000.000000Save

Line direct execution times (direct-seconds) are sorted longest times first. Direct execution time represents the time executing the line excluding the time inside any procedures called by the line.

Profiling
linehitsdirect-secondstotal-seconds
261181330.0348400.034840
412021540.0235410.023541
422021540.0210930.021093
1210.0098510.009851
301093630.0066450.006645
5099990.0046600.004660
2599990.0031200.003120
3199990.0012010.001201
2887700.0007230.000723
2499990.0006500.000650
2787700.0006290.000629
3299990.0006130.000613
2399990.0005990.000599
5199990.0005750.000575
393150.0002740.000274
40650.0000770.000077
443150.0000460.000046
1710.0000080.000008
1310.0000070.049042
43650.0000050.000005
4510.0000050.000005
1410.0000040.045052
1910.0000040.000004
3310.0000040.000004
4910.0000040.000004
1510.0000020.005247
2210.0000020.000002
3510.0000020.000002
4710.0000020.000002
5210.0000010.000001
16100
20100
21100
36100
37100
38100
48100

Conclusion

Locate execution bottlenecks.

Copyright Polar Engineering, Inc.