note 46198 added to function.var-export

From: Date: Sat, 02 Oct 2004 00:10:13 +0000
Subject: note 46198 added to function.var-export
Groups: php.notes 
Request: Send a blank email to php-notes+get-77722@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.var-export.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46198 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46198&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46198&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77722) next »