You can use the Pepperfish profiler to find bottlenecks in scripts. The profiler has two modes: time and call. The time mode tracks the amount of time the code takes to execute, the call mode tracks the number of calls to functions within the code. The recommended profiling method is time (default = time).
Read the comments in the code for more information.
To add the profiler to your project:
- Copy the Pepperfish profiler code into a new shared module, like pepperfish.
require 'pepperfish'at the top of the script to be profiled.
- Add the following before the section of code to be profiled:
profiler = newProfiler() profiler:start()
- And the following immediately after it:
profiler:stop() local outfile = io.open( "profile.txt", "w+" ) profiler:report( outfile ) outfile:close()
- The results are stored in a file called profile.txt (you change the name).
To check calls rather than time (call mode) simply change the code from step three to the following:
profiler = newProfiler('call') profiler:start()