Created
February 6, 2014 16:06
-
-
Save sandyUni/8847199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* test some performance between this and parent | |
*/ | |
function microtime_float() | |
{ | |
list($usec, $sec) = explode(" ", microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
/* | |
$time_start = microtime_float(); | |
/// | |
$time_end = microtime_float(); | |
$time = $time_end - $time_start; | |
*/ | |
class base1{ | |
public $a; | |
} | |
class base2{ | |
public static $a; | |
} | |
class sonfrombase1 extends base1{ | |
public function __construct($b) { | |
$this->a=$b; | |
} | |
public function run(){ | |
for($i=0;$i<10000000;$i++){ | |
$this->a++; | |
} | |
} | |
} | |
class sonfrombase2 extends base2{ | |
public function __construct($b) { | |
parent::$a=$b; | |
} | |
public function run(){ | |
for($i=0;$i<10000000;$i++){ | |
parent::$a++; | |
} | |
} | |
} | |
$son1=new sonfrombase1(0); | |
$time_start = microtime_float(); | |
$son1->run(); | |
$time_end = microtime_float(); | |
echo 'son1: '; | |
echo $time_end-$time_start; | |
echo '<br>'; | |
$thistime=$time_end-$time_start; | |
$son2=new sonfrombase2(0); | |
$time_start = microtime_float(); | |
$son2->run(); | |
$time_end = microtime_float(); | |
echo 'son2: '; | |
echo $time_end-$time_start; | |
echo '<br>'; | |
$parenttime=$time_end-$time_start; | |
if($thistime>$parenttime){ | |
echo "static has high performance: up to "; | |
echo ($thistime-$parenttime)/$parenttime; | |
echo "% time comsuming"; | |
} | |
else{ | |
echo "local has high performance: up to "; | |
echo ($parenttime-$thistime)/$thistime*100; | |
echo "% time comsuming"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment