Originally posted by orang
I do some benchmarking. It shows that using serialize is faster then using an "include".
i read this and was thinking to myself: no way, including a file would be much faster then grabbing a files contents an then unserializing, but like you i did some benchmarking of my own and, i'll be damned, unserializing does have a slight edge. this is the test i did:
method #1
test_array.php
<?php
$array = array(
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five',
6 => 'six',
7 => 'seven',
8 => 'eight',
9 => 'nine',
10 => 'ten'
);
?>
and then...
include('test_array.php');
method #2
test_serialized.txt
a:10:{i:1;s:3:"one";i:2;s:3:"two";i:3;s:5:"three";i:4;s:4:"four";i:5;s:4:"five";i:6;s:3:"six";i:7;s:5:"seven";i:8;s:5:"eight";i:9;s:4:"nine";i:10;s:3:"ten";}';
and then...
$contents = file_get_contents('test_serialized.php');
$array = unserialize($contents);