/** * use magic 0.31868386268616s * not use magic 0.11876797676086s */ class Test { private $varstr = "123"; function __get($name) { return $this->varstr; } } function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); $i = 0; while ($i<100000) { $i++; $t = new Test(); $t->varstr; } $time_end = microtime_float(); $time = $time_end - $time_start; echo "Did nothing in $time seconds\n";
建议尽量少用PHP魔法函数
时间: 2024-10-17 06:26:24