[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: profiling lua
- From: Adrian Sietsma <adrian_groups@...>
- Date: Sun, 30 Jan 2005 05:07:55 +1000
some fun with debug hooks
local f0 = function() end
local f1 = function() return math.sin(math.cos(math.random())) end
local n, n1 = 0
debug.sethook(function() n=n+1 end,"",1) -- hook every instruct
local t = f1(23)
this allows you to count lua instructions for any given code path.
it's not a cpu time model, but it's interesting to see the results of
code changes, and you don't need to loop to get a meaningful result,
unlike trying to time a function.
caveat - this only counts lua instructions - a 10-deep metatable lookup
still counts as one instruction.