note 46198 deleted from function.var-export by tomsommer

From: Date: Sat, 02 Oct 2004 16:58:13 +0000
Subject: note 46198 deleted from function.var-export by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77755@lists.php.net to get a copy of this message
Note Submitter: jnehle at gmail dot com ---- Here is a script I wrote to compare serialize/unserilize and var_export/eval <? $arraysize = 1000; $runs = 1000; for($i = 0; $i < $arraysize; $i++ ) { $array[] = $arraysize-$i; } $starttime = microtime_float(); for($i = 0; $i < $runs; $i++) { $serialized = serialize($array); $temp_array = unserialize($serialized); } print("$runs serializations/unserializations took ".(microtime_float() - $starttime)." seconds<br />"); $starttime = microtime_float(); for($i = 0; $i < $runs; $i++) { $arraystring = var_export($array, true); eval('$temp_array = '.$arraystring.';'); } print("$runs exports/evals took ".(microtime_float() - $starttime)." seconds<br />"); print('Serialized array is '.strlen(serialize($array)).' bytes<br />'); print('Exported array is '.strlen(var_export($array, true)).' bytes<br />'); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } ?> The output, when run on my webserver, was: 1000 serializations/unserializations took 4.1001060009003 seconds 1000 exports/evals took 10.164078950882 seconds Serialized array is 11792 bytes Exported array is 13792 bytes It seems that serialize/unserialize usually is between 2 - 3 times faster than var_export/eval

« previous php.notes (#77755) next »