lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> On Feb 28, 2017, at 7:54 PM, Daurnimator <> wrote:
> On 1 March 2017 at 08:56, Valerio Schiavoni <> wrote:
>> Hello
>> is it possible somehow to measure how much time the LuaVM spends to allocate
>> heap memory during the execution of a program?
>> Is there some debug flag that shows this information?
>> Thanks
>> --
>> Valerio
> You could do so by writing own allocator that takes a timing measurements.
> You can either use lua_setallocf() if you're wrapping the existing
> allocator, or otherwise pass your own allocator to lua_newstate().

I would, however, be very careful with such an approach. A custom allocator is basically a wrapper around realloc(), which of course is (typically) a fast function. If you are not careful the overhead of any instrumentation calls (e.g. getting an OS timestamp counter before/after) will exceed the time taken to make the realloc().