[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: heap allocation time?
- From: Tim Hill <drtimhill@...>
- Date: Tue, 28 Feb 2017 22:09:35 -0800
> On Feb 28, 2017, at 7:54 PM, Daurnimator <firstname.lastname@example.org> wrote:
> On 1 March 2017 at 08:56, Valerio Schiavoni <email@example.com> wrote:
>> 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?
> 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().