呵呵,我想二楼是没有完全弄清我的意思。我的程序有N多行,运行比较慢,我想看看到底哪行最费时间。我只知道PEAR 有个包是能完成这个功能的。苦于不知其名称。希望知道的XDJM告诉一声。^_^

解决方案 »

  1.   

    // 获得当前时间含毫秒
    function microtime_float()
    {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
    }
    // 获得开始毫秒数
    $time_start = microtime_float();
    //结束时间
    $time_end = microtime_float();
    //时间耗时
    $time = $time_end - $time_start;
    echo sprintf("%01.5f", $time);每隔一段代码加个输出耗时输出,应该能知道在哪个地方慢
      

  2.   

    在手册里搜索“declare”,其中示例代码可以完成你需要的功能!<?php
    // A function that records the time when it is called
    function profile ($dump = FALSE)
    {
        static $profile;    // Return the times stored in profile, then erase it
        if ($dump) {
            $temp = $profile;
            unset ($profile);
            return ($temp);
        }    $profile[] = microtime ();
    }// Set up a tick handler
    register_tick_function("profile");// Initialize the function before the declare block
    profile ();// Run a block of code, throw a tick every 2nd statement
    declare (ticks=20) {    for ($x = 1; $x < 50; ++$x) {
            echo similar_text (md5($x), md5($x*$x)), "<br />;";
        }}// Display the data stored in the profiler
    print_r (profile (TRUE));
    ?>
      

  3.   

    唠叨这个是按照低级语句显示时间的。不是按照程序的语句显示每条耗时多少的啊。我希望的结果像下面这个样子:
    line 1:0.001 sec
    line 2:0.02  sec
    line 3:0.03  sec 
    ....
    ....
    请问有这样的现成的package么?
      

  4.   

    关注此帖 
    PEAR 中记得有个PHPUnit 包 可能有楼主需要的功能,楼主可以看一下
    但是好像也不是单句输出时间 应该是模块化的
    比如 一个函数 或者 一个if。。else。。