Jump to content

Witch is Faster?


Monkuar

Recommended Posts

Using this

$rowbg = $rowbg == 'ce' ? 'ce bc1' : 'ce';

 

or using this:

 

 $color_one = 'ce bc1'; 
   $color_two = 'ce'; 
   static $i = 0;
   $color = ($i % 2) ? $color_one : $color_two;
   $i++;

 

for Alternating colors?

 

^^ ?

Link to comment
Share on other sites

Quicker? You won't see a difference until you put this in a loop that is processing millions of entries. And even then, compared to the other parts of your code, the time it takes to process this is negligible.

 

But, I would go with the first because it uses 1 variable vs 4, and is cleaner code.

 

But then again, I would probably be using Smarty for my templates, which has an alternate method in it, so I wouldn't have this code at all :)

Link to comment
Share on other sites

Quicker? You won't see a difference until you put this in a loop that is processing millions of entries. And even then, compared to the other parts of your code, the time it takes to process this is negligible.

 

But, I would go with the first because it uses 1 variable vs 4, and is cleaner code.

 

But then again, I would probably be using Smarty for my templates, which has an alternate method in it, so I wouldn't have this code at all :)

 

Smarty?

 

Im not trying to be mean ahah sorry

Link to comment
Share on other sites

For small projects, don't bother with it. But for any bigger site, I find it very handy. Also, I tend to develop the PHP and someone else does the HTML/CSS...so it REALLY helps with the separation of responsibilities.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.