Actually, my 'don't know' was more like 'does anyone know?' .

But I figured I could find that out for myself.

Wrote a small script that creates an array (numeric indexed range) of
10,000 elements.

Then it calls array_reverse() on it 100 times.

This took a little more than 3 secs. on a P3, which is relatively slow IMO.

Ofcourse two calls won't really hurt if you have a fast server.

A larger array of 100,000 elements took more then 30 secs. (hit the timelimit) ..

So the speed is clearly affected by the size of the array, *maybe* even by the size of 
the elements ..

Here's the code I used to test:

<?php

   set_time_limit(3600);

   $arr = range(1, 10000);


   start_clock();

   for ($i = 0; $i < 100; $i++)
   {
      array_reverse($arr);
   }

   echo(get_clock() . "\n");


   // timer functions

   function start_clock()
   {
      global $start;

      $start = microtime();
   }

   function get_clock()
   {
      global $start;

      $stop = microtime();

      $start = split(" ", $start);
      $stop = split(" ", $stop);

      $start = (float)$start[0] + $start[1];
      $stop = (float)$stop[0] + $stop[1];

      $time = $stop - $start;

      $htime = (int)($time / 3600);
      $time -= ($htime * 3600);

      $mtime = (int)($time / 60);
      $time -= ($mtime * 60);

      $stime = ((int)($time * 100) / 100);

      $stime = ereg_replace("\.", "s", $stime);

      if ($htime)
      {
         $clock = $htime . "H";
      }

      if ($mtime)
      {
         $clock .= $mtime . "m";
      }

      return $clock . $stime . "h";
   }
?>


On Thu, 10 Jan 2002 05:54:49 -0500, Gerard Samuel wrote:

>Thats my biggest concern now, performance with whatever alternatives 
>that can be dreamed up...
>Anyway, its 6 in the morning, time for sleep.  Maybe Ill dream up 
>something else....
>
>[EMAIL PROTECTED] wrote:
>
>> 
>> You are right, I should've known (used it before) ..
>> 
>> Ofcourse you could do an array_reverse() before and after,
>> don't know about the performance impact of that however.
>> 
>> bvr.
>> 
>> 
>>>array_pop() and array_shift are *different* :)
>>>
>>>array_pop() takes an element off the END of the array.
>>>array_shift() takes an element off the START of the array.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to