全部博文(42)
分类:
2008-10-25 01:05:15
<?php
$xtimes = 100000;
$att = '';
for ($i=0;$i<$xtimes;$i++) {
$att .= "\r\n\tpublic \$var$i = $i;";
}
$s = <<<END
<?php\r\n
class MC {
$att
\r\n
}\r\n
END;
$s .= '
$xn = ' . $xtimes . ';
class Setter {
public $n;
private $x = array();
private function __get($nm) {
if (isset($this->x[$nm])) {
$r = $this->x[$nm];
return $r = $this->x[$nm];;
} else {
return false;
}
}
private function __set($nm, $val) {
if (!isset($this->x[$nm])) {
$this->x[$nm] = $val;
}
}
private function __isset($nm) {
return isset($this->x[$nm]);
}
private function __unset($nm) {
unset($this->x[$nm]);
}
}
$foo = new Setter();
$star = microtime(1);
for ($i=0; $i<$xn;$i++) {
$var = "var$i";
$foo->$var = $i;
}
$out = microtime(1) - $star;
print "\n";
$foo2 = new MC();
$star = microtime(1);
for ($i=0; $i<$xn;$i++) {
$var = "var$i";
$foo2->$var = $i;
}
$out .= " -- " . (microtime(1) - $star);
print $out . " (this file is save at " . __FILE__ . \')\';
';
file_put_contents('testxxx.php', $s);
require 'estxxx.php';
unlink('testxxx.php'); // 把这行注释掉就可以看生成的文件对不对
?>