How to Profile a Lua Script using Pepperfish

How to Profile a Lua Script using Pepperfish: 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:

  1. Copy the Pepperfish profiler code into a new shared module, like pepperfish.
  2. Add require 'pepperfish' at the top of the script to be profiled.
  3. Add the following before the section of code to be profiled:
    profiler = newProfiler()
    profiler:start()
  4. And the following immediately after it:
    profiler:stop()
    
    local outfile = io.open( "profile.txt", "w+" )
    profiler:report( outfile )
    outfile:close()
  5. 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()

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.