PHP function calls have quite some overhead

Apparently $array === (array) $array is significantly faster than is_array($array) for very small arrays. I have posted a detailed benchmark script which seems to concur: for approximately 40-50 bytes, like an array containing 5-6 integers (I am on 64 bit) or 5-6 of 8 byte strings this tricky is definitely faster. For anything larger, the function call overhead seems to be smaller than the variable copy, cast, identity comparison time.

Comments

At the language shootout

At the language shootout (http://shootout.alioth.debian.org/), I looked at the binary trees benchmark in PHP. Moving the check for whether a node is a leaf node or not into the calling function cut the number of function calls in half, and reduced execution time by 35%.

Or in other words, for what amounts to basically doing nothing but traversing a binary tree, the overhead from making the recursive function call accounts for about 70% (!!!) of total execution time.

Function calls in PHP remain the most expensive of just about any mainstream language: http://shootout.alioth.debian.org/u32/benchmark.php?test=binarytrees&lan...

Hello,I love reading through

Hello,I love reading through your blog, I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.quilted coats// girls winter coats// winter coats 2012// parka coats for women// mens trench coat// leopard print coat//

black diamond pendants for

black diamond pendants for what amounts to basically doing nothing but traversing a binary tree, the overhead from making the recursive function call accounts for about 70% (!!!) of total execution time.