Skip to content

Instantly share code, notes, and snippets.

@tobiassjosten
Created August 5, 2010 18:54
Show Gist options
  • Save tobiassjosten/510192 to your computer and use it in GitHub Desktop.
Save tobiassjosten/510192 to your computer and use it in GitHub Desktop.
<?php
function a(array $a) {}
for ($i = 1; $i < 1000000; $i++) @a('');
<?php
function a($a)
{
if (is_array($a)) {}
}
for ($i = 1; $i < 1000000; $i++) a('');
<?php
function a(array $a) {}
for ($i = 1; $i < 1000000; $i++) a(array());
<?php
function a($a)
{
if (is_array($a)) {}
}
for ($i = 1; $i < 1000000; $i++) a(array());
tobias@laptop:~$ time php benchmark1a.php
real 0m6.895s
user 0m4.480s
sys 0m1.280s
tobias@laptop:~$ time php benchmark1b.php
real 0m5.837s
user 0m3.316s
sys 0m2.444s
tobias@laptop:~$ time php benchmark2a.php
real 0m3.447s
user 0m2.044s
sys 0m1.144s
tobias@laptop:~$ time php benchmark2b.php
real 0m5.882s
user 0m3.220s
sys 0m2.648s
@dmitrig01
Copy link

Hm. So I did a bit more testing:
with an empty arary instead of 'a':
$ time php 1.php # array
real 0m1.531s
$ time php 1.php # is_array
real 0m1.059s

However, with array('foo')

$ time php 1.php #array
real 0m0.932s
$ time php 1.php #is_array
real 0m1.205s

@tobiassjosten
Copy link
Author

I tried without the @ error suppression too. That put a serious dent in the performance. Without it you're definitely right on signature checking being faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment