note 76099 added to function.var-export
| From: | stangelanda at arrowquick dot com | Date: | Fri, 29 Jun 2007 23:20:48 +0000 |
| Subject: | note 76099 added to function.var-export | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128099@lists.php.net to get a copy of this message | ||
I have been looking for the best method to store data in cache files.
First, I've identified two limitations of var_export verus serialize. It can't store
internal references inside of an array and it can't store a nested object or an array
containing objects before PHP 5.1.0.
However, I could deal with both of those so I created a benchmark. I used a single array containing
from 10 to 150 indexes. I've generate the elements' values randomly using booleans,
nulls, integers, floats, and some nested arrays (the nested arrays are smaller averaging 5 elements
but created similarly). The largest percentage of elements are short strings around 10-15
characters. While there is a small number of long strings (around 500 characters).
Benchmarking returned these results for 1000 * [total time] / [iterations (4000 in this case)]
serialize 3.656, 3.575, 3.68, 3.933, mean of 3.71
include 7.099, 5.42, 5.185, 6.076, mean of 5.95
eval 5.514, 5.204, 5.011, 5.788, mean of 5.38
Meaning serialize is around 1 and a half times faster than var_export for a single large array.
include and eval were consistently very close but eval was usually a few tenths faster (eval did
better this particular set of trials than usual). An opcode cache like APC might make include
faster, but otherwise serialize is the best choice.
----
Server IP: 208.69.120.35
Probable Submitter: 207.32.22.145
----
Manual Page -- http://www.php.net/manual/en/function.var-export.php
Edit -- https://master.php.net/note/edit/76099
Del: integrated -- https://master.php.net/note/delete/76099/integrated
Del: useless -- https://master.php.net/note/delete/76099/useless
Del: bad code -- https://master.php.net/note/delete/76099/bad+code
Del: spam -- https://master.php.net/note/delete/76099/spam
Del: non-english -- https://master.php.net/note/delete/76099/non-english
Del: in docs -- https://master.php.net/note/delete/76099/in+docs
Del: other reasons-- https://master.php.net/note/delete/76099
Reject -- https://master.php.net/note/reject/76099
Search -- https://master.php.net/manage/user-notes.php