php calculate script execution time

WBOY
Release: 2016-08-08 09:29:14
Original
1130 people have browsed it

<code><span>//修改php的默认时区</span>
date_default_timezone_get(<span>'PRC'</span>);

<span>//使用微妙计算php脚本执行时间</span><span>echo</span> microtime(); <span>echo</span><span>" 返回当前unix时间戳和微秒数"</span>;
<span>echo</span><span>"<br>"</span>;


<span><span>class</span><span>Timer</span>{</span><span>private</span><span>$startTime</span>;
    <span>private</span><span>$stopTime</span>;

    <span><span>function</span><span>__construct</span><span>()</span>{</span><span>$this</span>->startTime=<span>0</span>;
        <span>$this</span>->stopTime=<span>0</span>;
    }

    <span><span>function</span><span>start</span><span>()</span>{</span><span>$this</span>->startTime=microtime(<span>true</span>);
    }

    <span><span>function</span><span>stop</span><span>()</span>{</span><span>$this</span>->stopTime=microtime(<span>true</span>);

    }

    <span><span>function</span><span>spent</span><span>()</span>{</span><span>return</span> round((<span>$this</span>->stopTime - <span>$this</span>->startTime),<span>4</span>);
    }



}

<span>$timer</span>= <span>new</span> Timer();
<span>$timer</span>->start();
usleep(<span>1000</span>);
<span>$timer</span>->stop();

<span>echo</span><span>"执行该脚本用时<b>"</span>.<span>$timer</span>->spent().<span>"</b>秒<br>"</span>;</code>
Copy after login

The above introduces the PHP script execution time calculation, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!