string cast

日付 2018.11.21
タイトル string cast
本文
set_time_limit(0);
$cnt = 1000000;

class A {
	public function __toString() {
		return 'afdafdsafda';
	}
}
$a = new A();
$b = 'afdafdsafda';


for ($i = 0; $i < $cnt; $i++) {
	// warmup loop
	$x = 1 + 1;
	$y = $x;
}
$st = getmicrotime();
print "warmup ".(getmicrotime() - $st)."\n";

$st = getmicrotime();
for ($i = 0; $i < $cnt; $i++) {
	$x = (string)$a;
}
print "first ".(getmicrotime() - $st)."\n";

$st = getmicrotime();
for ($i = 0; $i < $cnt; $i++) {
	$y = (string)$b;
}
print "second ".(getmicrotime() - $st)."\n";

$st = getmicrotime();
for ($i = 0; $i < $cnt; $i++) {
	$y = $b;
}
print "third ".(getmicrotime() - $st)."\n";

exit;


warmup 9.7990036010742E-5
first 14.120208978653
second 0.10936617851257
third 0.091479778289795