Re: Method call overhead
On Wed, Jun 3, 2015 at 3:33 PM, Brian Moon <[email protected]> wrote:
> On 6/2/15 22:30 , Bishop Bettini wrote:
>> I've measured the overhead for method calls in a variety of environments
>> (Amazon, Travis, and 3v4l). The results are reliable and here's 3v4l
>> <http://3v4l.org/NsjJR>.
>>
>> Some observations. First, as expected, direct calls are faster than
>> static
>> object calls, which are faster than object calls. Second, in absolute
>> times PHP7 outperforms HHVM3 substantially. Kudos, really impressive.
>>
>> My question though is on relative times. Method call overhead is
>> consistently 50% to 150% over a direct call. Is my experiment invalid, or
>> is this overhead expected? Is the overhead in the allocation,
>> deallocation, GC?
>>
> This is a better representation of what you are trying to show. It removes
> all the magic call back stuff that could be adding to the slowness you are
> seeing. In addition, it does not create a new object on every call for the
> object method. Creating a new object is going to explicitly slow things
> down. But, it's not related to the call time.
>
Interesting data. Regarding your original question, I would expect
method calls to be somewhat more expensive since even with a known
method name there's polymorphism to take into account. I wouldn't
expect it to be massively more, but non-zero.
I would still recommend using Callgrind as Mike suggested. It's going
to give you much more reliable (and useful) time numbers than
microtime().
-Sara
Thread (12 messages)