Difference between revisions of "profile"

(Documentation and source code)
(profile.lua)
 
Line 1: Line 1:
 
== profile.lua ==
 
== profile.lua ==
profile.lua is a real-time, non-intrusive tool for finding bottlenecks in your game. You don't have to modify any of your existing code to use this tool. You require the profiler and tell it when to start/stop collecting data. It's good to reset the profiler every 100 frames so you can look for bottlenecks in real-time.
+
profile.lua is a small module used for finding bottlenecks in your Lua code. To use the profiler, you need to require the profile.lua file and specify when to start or stop collecting data. Once you are done profiling, a report is generated, describing:
 +
 
 +
* which functions were called most frequently and
 +
* how much time was spent executing each function
 +
 
 +
== Example ==
 +
<source lang="lua">
 +
-- setup
 +
function love.load()
 +
  love.profiler = require('profile')
 +
  love.profiler.start()
 +
end
 +
 
 +
-- generates a report every 100 frames
 +
love.frame = 0
 +
function love.update(dt)
 +
  love.frame = love.frame + 1
 +
  if love.frame%100 == 0 then
 +
    love.report = love.profiler.report(20)
 +
    love.profiler.reset()
 +
  end
 +
end
 +
 
 +
-- prints the report
 +
function love.draw()
 +
  love.graphics.print(love.report or "Please wait...")
 +
end
 +
</source>
  
 
== Documentation and source code ==
 
== Documentation and source code ==

Latest revision as of 09:10, 9 October 2024

profile.lua

profile.lua is a small module used for finding bottlenecks in your Lua code. To use the profiler, you need to require the profile.lua file and specify when to start or stop collecting data. Once you are done profiling, a report is generated, describing:

  • which functions were called most frequently and
  • how much time was spent executing each function

Example

-- setup
function love.load()
  love.profiler = require('profile') 
  love.profiler.start()
end

-- generates a report every 100 frames
love.frame = 0
function love.update(dt)
  love.frame = love.frame + 1
  if love.frame%100 == 0 then
    love.report = love.profiler.report(20)
    love.profiler.reset()
  end
end

-- prints the report
function love.draw()
  love.graphics.print(love.report or "Please wait...")
end

Documentation and source code

https://github.com/2dengine/profile.lua

https://2dengine.com/doc/profile.html

Other Languages