John Holmes wrote:
From: "Aaron Voisine" <[EMAIL PROTECTED]>

I read in the docs several comments that $_SESSION is slower that other
arrays. One
comment even had benchmarking info indicating it was about half as
fast. I don't understand
why this should be. Isn't $_SESSION just a normal super global array
like any other, except that it get serialized and written to disk *once at the end* of a
request? Why on earth would this impact the performance of reading and
writing in the middle of a request? Is there some
funkyness going on under the covers that I'm missing? Can it be made to
work as I described?


Do you have links to these "docs"??

The following code gives me this:
Normal $val: 9.4890594482422E-05
Session var: 1.1920928955078E-05

<?php

function gt()
{
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);
}

session_start();

$s1 = gt();
$val['key'] = array('foo');
$e1 = gt();

$s2 = gt();
$_SESSION['key'] = array('foo');
$e2 = gt();

echo 'Normal $val: ' . ($e1 - $s1) . '<br />Session var: ' . ($e2-$s2);

?>

Sligtly modified code, $_SESSION is almost always faster then regular variable. I even tried testing $_SESSION first, then $val, same result. Now why is it so?


<?php

function gt()
{
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);
}

session_start();
$val = array();

$s1 = gt();
for($i = 0; $i < 50000; $i++) {
  $val['key' . $i] = array('foo');
}
$e1 = gt();

$s2 = gt();
for($i = 0; $i < 50000; $i++) {
  $_SESSION['key' . $i] = array('foo');
}
$e2 = gt();

echo 'Normal $val: ' . ($e1 - $s1) . '<br />Session var: ' . ($e2-$s2);

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to