Interesting.
You're not quite testing like for like here, as the function
is doing more
work than the include. That said, it should not cause what
you're seeing.
Having modified your example to be a like-for-like, I saw the
difference
disappear. I didn't expect this, so I dug a bit deeper.
In my modified test I had written the function "properly",
making sure all
the variables were VARed and the returntype of the function
was specified
and that sort of thing.
So I started to de-factor the changes in my code, bringing it
back to your
version.
When I removed the returntype: no difference.
When I removed the VARing: the discrepancy came back.
When I selectively altered the VARing, it seemed to be the i
variable that
was causing the performance hit (makes sense, as it's the
main player in
the loop, and it's the loop slowing down).
I suspect it's because when the code is compiled, access to
public
variables are done via getter methods, which will have some
overhead. When
using local variables: they'll be accessed directly.
All the more reason to always VAR one's variables.
--
Adam