speed test to class with public variable and function vs static variable and function


Currently refreshing the oops concept in php as i worked in drupal cms which almost functional oriented derived cms.

public variable and function inside class:

   /**
 *
 * Used to list the brands in the car
 * class:car
 * function:carlist()
 *
 */
class car {
    var $car = array('benz'=>'benz','mahinder'=>'mahinder','bmw'=>'bmw','honda'=>'honda','hundai'=>'hundai','tata'=>'tata');
        public function carlist(){
        return $this->car['benz'].' </br> '. $this->car['mahinder'].' </br> '. $this->car['bmw'].' </br> '. $this->car['honda'].' </br> '. $this->car['hundai'].' </br> '. $this->car['tata'].' </br> ';
        
    }    
    
}
$startTime = microtime(true);
$car = new car;
echo $car->carlist();
echo "Time:  " . number_format(( microtime(true) - $startTime), 5) . " Seconds\n";

Result:

Time: 0.00003

static variable and function inside class:

/**
 *
 * Used to list the brands in the car
 * class:car
 * Varible Type:static
 * function Type:static
 * function:carlist()
 *
 */
class cars {
    static $car = array('benz'=>'benz','mahinder'=>'mahinder','bmw'=>'bmw','honda'=>'honda','hundai'=>'hundai','tata'=>'tata');
        static function carlist(){
        return cars::$car['benz'].' </br> '. cars::$car['mahinder'].' </br> '. cars::$car['bmw'].' </br> '. cars::$car['honda'].' </br> '. cars::$car['hundai'].' </br> '. cars::$car['tata'].' </br> ';
        
    }    
    
}
 $startTimes = microtime(true);
echo  cars::carlist();
echo "Time:  " . number_format(( microtime(true) - $startTimes), 5) . " Seconds\n";

Result:

Time: 0.00001

Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , ,
Posted in php

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
April 2015
M T W T F S S
« Mar   May »
 12345
6789101112
13141516171819
20212223242526
27282930  
Follow me on Twitter
Blog Stats
  • 72,827 hits
%d bloggers like this: