Sheerpower's built-in profiler generates a report showing the execution time and
frequency of each routine. By identifying the routines with the longest
execution times, you can focus your
optimization efforts where they will have the greatest impact on performance.
Sheerpower includes a built-in code profiler. It is used for:
- Identifing Bottlenecks: Pinpoints slow or inefficient parts of the code.
- Optimizing Performance: Helps make data-driven decisions to improve code efficiency.
- Providing Detailed Insights: Provides comprehensive statistics on execution times and resource usage.
- Improving Debugging: Works alongside debugging tools to provide a complete picture of code performance.
- Producing Cost-Effective Development: Reduces time spent on trial-and-error optimizations,
streamlining the development process.
To activate it, add these statements to the
top of your code:
debug on
stats on
Then, after you have run your code long enough or just before your program ends:
list stats
This writes profiling information to a file named
myprogram_stats.txt where
myprogram is the name of your program. The statistics file contains the names of every routine
that is called. For each routine the amount of elapsed time spent in that routine and a count is provided.
The count is the maximum number of times any statement within the routine was executed.
At the end of the file is a list of the top 20 routines that took the longest elapsed time to execute. This
information lets you focus on which routines need to be optimized the most.
debug on
stats on
for idx = 1 to 10
more_work
do_it
do_it2
next idx
list stats
stats off
debug off
stop
routine more_work
x=x+1
delay .05
end routine
routine do_it2
delay .2
x=x+1
end routine
routine do_it
delay .2
x=x+1
end routine
stop
Below is the profile as generated:
Sheerpower Profiling Statistics 07-SEP-2022 08:02:25
C:\Sheerpower\stats.spsrc
0.62 10 routine more_work
2.02 10 routine do_it2
2.00 10 routine do_it
***** Longest Executing Routines *****
2.02 10 routine do_it2
2.00 10 routine do_it
0.62 10 routine more_work
************************
--- End of stats ---
Note: You will need to
download Sheerpower
to try the profiling feature. Also note that profiling only works when running from source code
and not when running deployed (SPRUN) code.
In addition, individual blocks of code can be timed by using:
- START TIMER
- ... your code here ...
- print _elapsed // elapsed time in seconds since the last START TIMER
x = 90
start timer
for i=1 to 1_000_000
y = sin(x)
next i
print 'Elapsed time: '; _elapsed
Summary: The Importance of Profiling in Development
Profiling is a powerful built-in feature of SheerPower that helps developers
optimize performance by identifying routines that consume the most time and
resources. By targeting bottlenecks, the profiler allows developers to
concentrate their efforts where they will have the greatest impact,
significantly improving overall efficiency.
By providing detailed insights into execution times and routine call
frequencies, the profiler enables data-driven optimization, simplifies
debugging, and minimizes trial-and-error in development. This results in
faster, more cost-effective, and high-performing applications tailored to
business needs. Profiling turns the often complex process of optimization
into a precise and measurable task.