performance - Can lots of PHP if statement slow down my site -


i know there similar questions, couldn't answer mine. i'm building wordpress theme , there lots of options in backend. example address made fields every possible value hcard can contain. query options in 1 single query, have lots of if-statements create html. of course of isn't needed in cases.

    <?php      $address_settings = get_option( 'nothing_settings_address' ); ?>      <?php if( $address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ] ) : ?>         <?php $hcard_title = $address_settings[ 'hcard_given_name' ].' '.$address_settings[ 'hcard_family_name' ]; ?>     <?php elseif( $address_settings[ 'hcard_organization' ] ) : ?>         <?php $hcard_title = $address_settings[ 'hcard_organization' ]; ?>     <?php endif; ?>      <figure id="vcard-<?php echo $address_settings[ 'hcard_family_name' ]; ?><?php echo $address_settings[ 'hcard_given_name' ]; ?>" class="vcard one-third column" title="<?php echo $hcard_title; ?>" itemtype="http://www.data-vocabulary.org/person/" itemscope="itemscope">          <!-- photo -->         <img src="<?php echo $address_settings[ 'hcard_img' ]; ?>" alt="" class="photo" itemprop="photo">         <!-- alt redundant; image labeled context, leave empty (webaim) -->            <!-- caption -->         <figcaption>             <!-- profile -->             <section class="profile">                   <!-- name -->                 <?php if( $address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ] || $address_settings[ 'hcard_nickname' ] ) : ?>                 <header class="n" title="name">                     <?php if( $address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ] ) : ?>                     <span class="fn" itemprop="name">                         <?php if( $address_settings[ 'hcard_prefix' ] ) : ?>                             <span class="honorific-prefix"><?php echo $address_settings[ 'hcard_prefix' ]; ?></span>                         <?php endif; ?>                         <?php if( $address_settings[ 'hcard_given_name' ] ) : ?>                             <span class="given-name"><?php echo $address_settings[ 'hcard_given_name' ]; ?></span>                         <?php endif; ?>                         <?php if( $address_settings[ 'hcard_middle_name' ] ) : ?>                             <span class="additional-name"><?php echo $address_settings[ 'hcard_middle_name' ]; ?></span>                         <?php endif; ?>                         <?php if( $address_settings[ 'hcard_family_name' ] ) : ?>                             <span class="family-name"><?php echo $address_settings[ 'hcard_family_name' ]; ?></span>                         <?php endif; ?>                         <?php if( $address_settings[ 'hcard_suffix' ] ) : ?>                             <span class="honorific-suffix"><?php echo $address_settings[ 'hcard_suffix' ]; ?></span>                         <?php endif; ?>                     </span> <!--/ .fn -->                     <?php endif; ?>                     <?php if( $address_settings[ 'hcard_nickname' ] ) : ?>                         <span class="nickname" itemprop="nickname"><?php echo $address_settings[ 'hcard_nickname' ]; ?></span>                     <?php endif; ?>                 </header> <!--/ .n -->                 <?php endif; ?>               <!-- category -->             <?php if( $address_settings[ 'hcard_cat' ] ) : ?>             <section class="category" itemprop="category">                 <?php echo $address_settings[ 'hcard_cat' ]; ?>             </section>             <?php endif; ?>               <!-- links -->             <?php if( $address_settings[ 'hcard_note' ] ) : ?>             <section class="note" itemprop="note" >                 <?php echo $address_settings[ 'hcard_note' ]; ?>             </section>             <?php endif; ?>               <!-- birthday -->             <?php if( $address_settings[ 'hcard_bday' ] ) : ?>             <time class="bday" itemprop="bday" >                 <?php echo $address_settings[ 'hcard_bday' ]; ?>             </time>             <?php endif; ?>                   <!-- organization -->                 <?php if( $address_settings[ 'hcard_organization' ] || $address_settings[ 'hcard_unit' ] || $address_settings[ 'hcard_title' ] ) : ?>                 <div class="org" itemprop="affiliation" title="organization" itemscope="itemscope" itemtype="http://www.data-vocabulary.org/organization/">                     <?php if( $address_settings[ 'hcard_organization' ] ) : ?>                      <div class="vcard">                         <span class="organization-name fn" itemprop="name"><?php echo $address_settings[ 'hcard_organization' ]; ?></span>                             <?php if( $address_settings[ 'hcard_orga_street' ] || $address_settings[ 'hcard_orga_city' ] || $address_settings[ 'hcard_orga_state' ] || $address_settings[ 'hcard_orga_country' ] || $address_settings[ 'hcard_orga_postal_code' ] ) : ?>                             <div class="adr" itemprop="address" itemscope="itemscope" itemtype="http://data-vocabulary.org/address/">                                  <!-- address --><?php if( $address_settings[ 'hcard_orga_street' ] ) : ?>                                     <span class="street-address" itemprop="street-address"><?php echo $address_settings[ 'hcard_orga_street' ]; ?></span>                                 <?php endif; ?>                                  <!-- city --><?php if( $address_settings[ 'hcard_orga_city' ] ) : ?>                                     <span class="locality" itemprop="locality"><?php echo $address_settings[ 'hcard_orga_city' ]; ?></span>,                                 <?php endif; ?>                                  <!-- state --><?php if( $address_settings[ 'hcard_orga_state' ] ) : ?>                                     <?php if( $address_settings[ 'hcard_orga_state' ] ) :                                         $orga_state_title = $address_settings[ 'hcard_orga_state' ];                                     else :                                         $orga_state_title = $address_settings[ 'hcard_orga_state_short' ];                                     endif; ?>                                     <?php if( !$address_settings[ 'hcard_orga_state' ] ) :                                         $orga_state = $address_settings[ 'hcard_orga_state' ];                                     else :                                         $orga_state = $address_settings[ 'hcard_orga_state_short' ];                                     endif; ?>                                     <abbr class="region" itemprop="region" title="<?php echo $orga_state_title; ?>"><?php echo $orga_state; ?></abbr>                                 <?php endif; ?>                                  <!-- zip --><?php if( $address_settings[ 'hcard_orga_postal_code' ] ) : ?>                                     <abbr class="postal-code" itemprop="postal-code" title="<?php echo $address_settings[ 'hcard_orga_postal_code' ]; ?>"><?php echo $address_settings[ 'hcard_orga_postal_code' ]; ?></abbr>                                 <?php endif; ?>                                  <!-- country --><?php if( $address_settings[ 'hcard_orga_country' ] || $address_settings[ 'hcard_orga_country_short' ]) : ?>                                     <?php if( $address_settings[ 'hcard_orga_country' ] ) :                                         $orga_country_title = $address_settings[ 'hcard_orga_country' ];                                     else :                                         $orga_country_title = $address_settings[ 'hcard_orga_country_short' ];                                     endif; ?>                                     <?php if( !$address_settings[ 'hcard_orga_country' ] ) :                                         $orga_country = $address_settings[ 'hcard_orga_country' ];                                     else :                                         $orga_country = $address_settings[ 'hcard_orga_country_short' ];                                     endif; ?>                                     <abbr class="country-name" itemprop="country-name" title="<?php echo $orga_country_title; ?>"><?php echo $orga_country; ?></abbr>                                 <?php endif; ?>                                  <!-- lat/lon (metadata) -->                                 <!-- integrate later. <span class="geo" itemprop="geo" itemscope="itemscope" itemtype="http://data-vocabulary.org/geo/">                                     <abbr class="latitude" itemprop="latitude" title="60.6060606060">60.6060606060</abbr>                                     <abbr class="longitude" itemprop="longitude" title="-60.6060606060">-60.6060606060</abbr>                                 </span>-->                              </div> <!--/ .adr -->                             <?php endif; ?>                     </div> <!--/ .vcard -->                     <?php endif; ?>                      <?php if( $address_settings[ 'hcard_unit' ] ) : ?>                         <span class="organization-unit"><?php echo $address_settings[ 'hcard_unit' ]; ?></span>                     <?php endif; ?>                      <?php if( $address_settings[ 'hcard_title' ] ) : ?>                         <span class="title" itemprop="title"><?php echo $address_settings[ 'hcard_title' ]; ?></span>                     <?php endif; ?>                  </div> <!--/ .org -->                 <?php endif; ?>                   <!-- location -->                 <?php if( $address_settings[ 'hcard_street' ] || $address_settings[ 'hcard_city' ] || $address_settings[ 'hcard_state' ] || $address_settings[ 'hcard_country' ] || $address_settings[ 'hcard_postal_code' ] ) : ?>                 <address class="adr" itemprop="address" title="location" itemscope="itemscope" itemtype="http://data-vocabulary.org/address/">                      <!-- address -->    <?php if( $address_settings[ 'hcard_street' ] ) : ?>                         <span class="street-address" itemprop="street-address"><?php echo $address_settings[ 'hcard_street' ]; ?></span>                     <?php endif; ?>                      <!-- city --><?php if( $address_settings[ 'hcard_city' ] ) : ?>                         <span class="locality" itemprop="locality"><?php echo $address_settings[ 'hcard_city' ]; ?></span>,                     <?php endif; ?>                      <!-- state --><?php if( $address_settings[ 'hcard_state' ] ) : ?>                         <?php if( $address_settings[ 'hcard_state' ] ) :                             $state_title = $address_settings[ 'hcard_state' ];                         else :                             $state_title = $address_settings[ 'hcard_state_short' ];                         endif; ?>                         <?php if( !$address_settings[ 'hcard_state' ] ) :                             $state = $address_settings[ 'hcard_state' ];                         else :                             $state = $address_settings[ 'hcard_state_short' ];                         endif; ?>                         <abbr class="region" itemprop="region" title="<?php echo $state_title; ?>"><?php echo $state; ?></abbr>                     <?php endif; ?>                      <!-- zip --><?php if( $address_settings[ 'hcard_postal_code' ] ) : ?>                         <abbr class="postal-code" itemprop="postal-code" title="<?php echo $address_settings[ 'hcard_postal_code' ]; ?>"><?php echo $address_settings[ 'hcard_postal_code' ]; ?></abbr>                     <?php endif; ?>                      <!-- country --><?php if( $address_settings[ 'hcard_country' ] || $address_settings[ 'hcard_country_short' ]) : ?>                         <?php if( $address_settings[ 'hcard_country' ] ) :                             $country_title = $address_settings[ 'hcard_country' ];                         else :                             $country_title = $address_settings[ 'hcard_country_short' ];                         endif; ?>                         <?php if( !$address_settings[ 'hcard_country' ] ) :                             $country = $address_settings[ 'hcard_country' ];                         else :                             $country = $address_settings[ 'hcard_country_short' ];                         endif; ?>                         <abbr class="country-name" itemprop="country-name" title="<?php echo $country_title; ?>"><?php echo $country; ?></abbr>                     <?php endif; ?>                      <!-- lat/lon (metadata) -->                     <!-- integrate later. <span class="geo" itemprop="geo" itemscope="itemscope" itemtype="http://data-vocabulary.org/geo/">                         <abbr class="latitude" itemprop="latitude" title="30.3030303030">30.3030303030</abbr>                         <abbr class="longitude" itemprop="longitude" title="-30.3030303030">-30.30303030</abbr>                     </span>-->                  </address> <!--/ .adr -->                 <?php endif; ?>                   <!-- contact -->                 <?php if( $address_settings[ 'hcard_url' ] ) : ?>                     <a class="url" href="<?php echo $address_settings[ 'hcard_url' ]; ?>"><?php echo $address_settings[ 'hcard_url' ]; ?></a>,                 <?php endif; ?>                 <?php if( $address_settings[ 'hcard_postal_code' ] ) : ?>                     <a href="mailto:<?php echo $address_settings[ 'hcard_email' ]; ?>" class="email"><?php echo $address_settings[ 'hcard_email' ]; ?></a>                 <?php endif; ?>                  <?php if( $address_settings[ 'hcard_work' ] || $address_settings[ 'hcard_private' ] || $address_settings[ 'hcard_mobile' ] || $address_settings[ 'hcard_fax' ] ) : ?>                 <ul itemscope="itemscope" itemtype="http://www.data-vocabulary.org/organization/">                     <?php if( $address_settings[ 'hcard_private' ] ) : ?>                         <li class="tel"><abbr class="type" title="home pref">home:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_private' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_private' ]; ?>"><?php echo $address_settings[ 'hcard_private' ]; ?></a></abbr></li>                     <?php endif; ?>                     <?php if( $address_settings[ 'hcard_work' ] ) : ?>                         <li class="tel"><abbr class="type" title="work">office:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_work' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_work' ]; ?>"><?php echo $address_settings[ 'hcard_work' ]; ?></a></abbr></li>                     <?php endif; ?>                     <?php if( $address_settings[ 'hcard_mobile' ] ) : ?>                         <li class="tel"><abbr class="type" title="mobile">mobile:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_mobile' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_mobile' ]; ?>"><?php echo $address_settings[ 'hcard_mobile' ]; ?></a></abbr></li>                     <?php endif; ?>                     <?php if( $address_settings[ 'hcard_fax' ] ) : ?>                         <li class="tel"><abbr class="type" title="fax">fax:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_fax' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_fax' ]; ?>"><?php echo $address_settings[ 'hcard_fax' ]; ?></a></abbr></li>                     <?php endif; ?>                 </ul>                 <?php endif; ?>             </section> <!--/ .profile -->         </figcaption> <!--/ .figcaption -->     </figure> 

i want theme fast. not fast possibly be. fast enough called "fast theme". stuff around theme. can these statements slow down?

the "if/then" statements won't big performance hit, experience kicking in php can cause bit of hit. re-write using bigger blocks of php , using echos html, so:

instead of:

<?php if ($this > $that) { echo 'this'; } ?> <p>this not that!</p> <?php if ($other < $every) { echo 'is'; } ?> <p>this not efficient.</p> /* , forth... */ 

you'd want this:

<?php    if ($this > $that) { echo 'this'; }   echo '<p>this not that!</p>';   if ($other < $every) { echo 'is'; }   echo '<p>this not efficient.</p>';   /* , forth... */ ?> 

edit more efficient approach (as mentioned mildlyinteresting):

<?php    var $output = '';    if ($this > $that) {     $output .= 'this';   }    $output .= '<p>this not that!</p>';    if ($other < $every) {     $output .= 'is';   }    $output .= '<p>this not efficient.</p>';   /* , forth... */    echo $output; ?> 

this not best example, think idea.

luke


Comments