EllisLab text mark
Advanced Search
     
Which is method is processed faster?
Posted: 22 July 2010 11:37 PM
Avatar
Joined: 2006-09-08
138 posts

Somewhere on here awhile ago I read that using this:

{if bla}
Bla
!
{/if}

{if no bla}
No Bla
!
{/if] 

...was faster than ...

{if bla)
Bla!
{if:else}
No Bla
!
{/if} 

Is that true with EE?

Along that line, is the script processed faster to use the faster conditional above or a relationship, when caching is involved?  Example:

A custom dropdown has the values “cherry” or “orange,”

{exp:channel:entries channel="MyBlog"}
  {if custom_field_dropdown
=="cherry"} Traverse City{/if}
  {if custom_field_dropdown
=="orange"} Florida{/if}
{
/exp:channel:entries} 

or a second channel “food” is made with entries “cherry” and “orange” with a body tag that says “Traverse City” and “Florida” and a relationship custom field is placed in “MyBlog” to “food”.

{exp:channel:entries channel="food" cache="yes" refresh="999"}
  {related_entries id
="custom_field_dropdown"}
    {body}
!
  
{/related_entries}
{
/exp:channel:entries} 


Remembered an article written about EE’s features page where it quicker renderings were achieved by some relationship concept.

 Signature 

Blair

 
Posted: 23 July 2010 02:45 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2004-03-22
12308 posts

Blair L,

With conditionals it is mainly a question of Parse order. So a simple one may complete before it gets to completing an advanced conditional. So not necessarily speed.

You can do your own speeds tests by flicking on your Display Template Debugging? under Output and Debugging

 Signature 

John Henry’s Website | Follow me on Twitter

 
Posted: 23 July 2010 02:57 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2006-09-08
138 posts

But in those specific examples, which theoretically should be quicker?

 Signature 

Blair

 
Posted: 23 July 2010 10:31 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-15
29075 posts

I am afraid you would have to test it. There are too many sever-specific variables for a hard and fast rule.

 
Posted: 24 July 2010 01:36 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2003-01-07
713 posts

Hi Blair,

{if logged_in_group_id == '1'}
     
<p>{total_queries} Total Queries<br />{memory_usage} of Memory<br />{elapsed_time} Seconds to Load</p>
{/if} 

We “speed test” every site we build while we’re building it. With EE 2.1.x you can add the above code to your site (I think the memory_usage tag is new to EE 2), and assuming you are a Super Admin (group_id 1), you should see these three measures of how your code is performing.

One concept to grasp about simple conditionals vs. advanced is that advanced parse really late during the page load and after the channel tags do. I’ve seen a lot of EE developers kill their speed by coding something like this in a template:

{if this_condition}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{if
:elseif another_condition}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{if
:else}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{
/if} 

Since the advanced conditionals parse AFTER the channel tags, EE runs all three channel tags every time the template loads, even though it will only display the results of one of them. It basically buys three pairs of shoes even though it can only ware one pair at a time. If any of those channel tags has the ability to return lots of entries, then you can run into issues.

{if this_condition}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{
/if}
{if another_condition}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{
/if}
{if things 
!= "this_condition" AND things != "another_condition"}
     {exp
:channel:entries}
          {content}
     {
/exp:channel:entries}
{
/if} 

Using simple conditionals that parse BEFORE the channel tags do, EE should only have to run one of the three channel tags per template load. if you have well-formed simple conditionals

Hope this helps you a bit in you quest for speed.

**Update: Take note of the last conditional, which is actually considered to be advanced by later builds of EE. So my final example uses two simple conditionals and one advanced. See this great post for more info on the subject: http://ellislab.com/forums/viewthread/168268/

 Signature 

NetRaising | a web services company


Custom Designed Dynamic Websites for Mission Driven Organizations

 
Posted: 24 July 2010 05:17 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2005-06-20
3997 posts

@Kurt, thanks very much. Nice write up!

@Blair L, does that help you out?

Cheers

Greg

 Signature 

   Purple Dogfish | Member of EE Pro Network | Follow me on Twitter

 
Posted: 24 July 2010 08:59 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2006-09-08
138 posts

There we go… That exactly what I was looking for!

... and it look me awhile, but this was the other question I was looking for http://ellislab.com/blog/entry/behind_the_curtain_part_four/

 Signature 

Blair

 
Posted: 25 July 2010 04:16 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2005-06-20
3997 posts

Hi Blair,

Excellent. Glad Kurt’s explanation helped sort that out. Please post back if you have further questions or problems.

Cheers

Greg

 Signature 

   Purple Dogfish | Member of EE Pro Network | Follow me on Twitter