$start= microtime(true);
echo $start."\n";
$end = microtime(true);
echo $end."\n";
echo ($end-$start)."\n";
立即学习“PHP免费学习笔记(深入)”;
$base_memory= memory_get_usage();
echo "Hello,world!\n";
$end_memory= memory_get_usage();
$peak_memory= memory_get_peak_usage();
echo $base_memory,"\t",$end_memory,"\t",($end_memory-$base_memory),"\t", $peak_memory,"\n";
立即学习“PHP免费学习笔记(深入)”;
$baseMemory= memory_get_usage();
class User
{
private $uid;
function __construct($uid)
{
$this->uid= $uid;
}
}
for($i=0;$i<100000;$i++)
{
$obj= new User($i);
if ( $i% 10000 === 0 )
{
echo sprintf( '%6d: ', $i), memory_get_usage(), " bytes\n";
}
}
echo " peak: ",memory_get_peak_usage(true), " bytes\n";
立即学习“PHP免费学习笔记(深入)”;
[root@localhostphpperf]# php52 memory.php
0: 93784 bytes
10000: 93784 bytes
……
80000: 93784 bytes
90000: 93784 bytes
peak: 262144 bytes
立即学习“PHP免费学习笔记(深入)”;
[root@localhostphpperf]# phpmemory.php
0: 634992 bytes
10000: 634992 bytes
……
80000: 634992 bytes
90000: 634992 bytes
peak: 786432 bytes
立即学习“PHP免费学习笔记(深入)”;
[root@localhostphpperf]# php56 memory.php
0: 224944 bytes
10000: 224920 bytes
……
80000: 224920 bytes
90000: 224920 bytes
peak: 262144 bytes
立即学习“PHP免费学习笔记(深入)”;
[root@localhostphpperf]# php7 memory.php
0: 353912 bytes
10000: 353912 bytes
……
80000: 353912 bytes
90000: 353912 bytes
peak: 2097152 bytes
立即学习“PHP免费学习笔记(深入)”;
$baseMemory= memory_get_usage();
class User
{
private $uid;
function __construct($uid)
{
$this->uid= $uid;
}
}
for($i=0;$i<100000;$i++)
{
$obj= new User($i);
$obj->self = $obj;
if ( $i% 5000 === 0 )
{
echo sprintf( '%6d: ', $i), memory_get_usage(), " bytes\n";
}
}
立即学习“PHP免费学习笔记(深入)”;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号