[xdebug-general] array_key_exists slow

From: André Hänsel <andre[@]webkr.de>
Date: Thu, 6 May 2010 17:18:31 +0200


at first: this is not directly Xdebug related, so feel free to hit the
delete button now. But maybe this is interesting anyway.

I have a piece of code to find out whether an entry is already in the
database. I tried 4 different implementations:

if (array_key_exists($id,$big_array))
        return $big_array[$id];

if (isset($big_array[$id]))
        return $big_array[$id];

if (mysql_num_rows(mysql_query('...')))
        return mysql_fetch_row(...);

if (my_isset($big_array[$id]))
        return $big_array[$id];

I found out that the first implementation is by far slower even than the
third one.

To determine the time share that is function call overhead I introduced
function my_isset($v) { return isset($v); }
and found that it is negligible.

So why is array_key_exists so extremely slow?

I found its implementation in
ev=php_5_2_9 in line 4657. I could not find the implementation of isset.

I put the profiler output files of all 4 implementations on
http://kundenweb.creations.de/usenet/xdebug/xdebug2.zip. The relevant calls
are in parse_3t_data -> parse_3t_data_db_article_data.

Received on Thu May 06 2010 - 16:25:13 BST

This archive was generated by hypermail 2.2.0 : Mon Jun 25 2018 - 06:00:04 BST