Difference between revisions of "profile"
(→Documentation and source code) |
(→profile.lua) |
||
Line 1: | Line 1: | ||
== profile.lua == | == profile.lua == | ||
− | profile.lua is a | + | 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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info