入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

PHP 统计执行时间

创建时间:2018-01-24 投稿人: 浏览次数:235
<?php

set_time_limit(0);

//计时函数
function G($start,$end="",$dec=4)
{
    static $_info = array();
    if (!empty($end))
    {
        if(!isset($_info[$end])) $_info[$end] = microtime(TRUE);
        $sconds = number_format(($_info[$end]-$_info[$start]), $dec) * 1000;
        echo "{$sconds}ms<br />";
    }
    else
    {
        $_info[$start] = microtime(TRUE);
    }
}

$redis = new Redis();
$redis->connect("127.0.0.1");

G("t");
$redis->pipeline();
for ($i=0; $i < 100000 ; $i++) { 
   $redis->set("test_{$i}", pow($i, 2));
   $redis->get("test_{$i}");
}
$redis->exec();
G("t","r");

G("m");
$redis->multi();
for ($i=0; $i < 100000 ; $i++) { 
   $redis->set("test_{$i}", pow($i, 2));
   $redis->get("test_{$i}");
}
$redis->exec();
G("m","i");

$redis->flushdb();

G("f");
for ($i=0; $i < 100000 ; $i++) { 
   $redis->set("test_{$i}", pow($i, 2));
   $redis->get("test_{$i}");
}
G("f","e");

?>
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像