Welcome Guest, Not a member yet? Register   Sign In
php mod % 3
#7

[eluser]John_Betong[/eluser]
Hi Pygon,

I was curious to see how much faster your code was so took the trouble to modify my code:

contoller
Code:
// Benchmark different methods  of calculating links
  $this->benchmark->mark('code_start');
  if (0===$test) { // slow method
    $data['joketitle']    = 'Five column using  <b>% 5</b>';
    foreach($result->result() as $row):
    $data['a'.($row->id % 5)][] = anchor('/joke/show/'
                                . $row->id, sprintf("&#x4d;  &nbsp;&nbsp;  %s", $row->id, $row->title));    
    endforeach;
      
  }else{
   $data['joketitle'] = 'Five column using  <b>$i++</b>';
   $i    = 0;
   $cols = 5;
   foreach($result->result() as $row) {
     if ($i == $cols ) {
       $i = 0;
     }
    $data['a'.$i][] = anchor('/joke/show/'
                    .$row->id, sprintf(" %d    &nbsp;&nbsp; %s",$row->id, $row->title));
                     $i++;
    }//endforeach
  }// end else
  $this->benchmark->mark('code_end');
  $data['joketitle'] .= ' Elapsed time ==> ' .$this->benchmark->elapsed_time('code_start','code_end');
&nbsp;
Test results shown in the title ("Five column using $i++ Elapsed time ==>"):
&nbsp;
&nbsp;&nbsp;using++

&nbsp;&nbsp;using %5
&nbsp;
Cheers,

John_Betong
&nbsp;


Messages In This Thread
php mod % 3 - by El Forum - 10-18-2007, 06:07 PM
php mod % 3 - by El Forum - 10-18-2007, 08:01 PM
php mod % 3 - by El Forum - 10-18-2007, 10:00 PM
php mod % 3 - by El Forum - 10-18-2007, 10:07 PM
php mod % 3 - by El Forum - 10-19-2007, 03:31 AM
php mod % 3 - by El Forum - 10-29-2007, 04:04 PM
php mod % 3 - by El Forum - 10-31-2007, 05:24 AM
php mod % 3 - by El Forum - 10-31-2007, 08:23 AM
php mod % 3 - by El Forum - 10-31-2007, 09:03 AM
php mod % 3 - by El Forum - 10-09-2008, 04:07 PM
php mod % 3 - by El Forum - 10-09-2008, 09:06 PM
php mod % 3 - by El Forum - 10-09-2008, 11:17 PM
php mod % 3 - by El Forum - 10-10-2008, 12:34 AM
php mod % 3 - by El Forum - 10-10-2008, 03:38 AM
php mod % 3 - by El Forum - 10-10-2008, 12:23 PM
php mod % 3 - by El Forum - 10-11-2008, 09:36 AM
php mod % 3 - by El Forum - 10-11-2008, 01:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB