我们怎么知道脚本?执行时间?面向对象编程
我很想知道这个脚本是否有助于了解 php 脚本的执行情况?
几毫秒的
<?php
$timestart = microtime(true);
/* Blah Blah here ... */
$timeend = microtime(true);
echo 'Execution Time : '.round((timeend - timestart) * 1000, 2);
?>
对于使用 OOP(面向对象编程),我有
想法。另外,我将制作一个脚本来解析文本文件(.txt),我可能会有 120 - 700 行,哪种方式更好地了解数据处理?
时间取决于行数吗?
I would love to know if this script is good to know the execution of php script ?
for miliseconds
<?php
$timestart = microtime(true);
/* Blah Blah here ... */
$timeend = microtime(true);
echo 'Execution Time : '.round((timeend - timestart) * 1000, 2);
?>
I have no ideas about using OOP (object-oriented programming) with it.
Also I'll make a script who will parse a text files (.txt), I'll have maybe 120 - 700 lines, which way is better to know the data treatment ?
Does the time depend on number of lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用我前段时间写的这个 Timer 类。一个优点是它是“增量”的,您可以在循环内启动计时器,并且它将附加开始和停止之间的时间。
请注意,如果您这样做,将需要相当长的时间来执行。
基本用法:
请注意,它是有限的,而且远不是最快的方法。创建和销毁类需要时间。当在“逻辑”循环内完成时,它会增加相当长的时间。但是要跟踪一些具有多个叠瓦循环或递归函数调用的复杂程序,这个东西就很珍贵了
I use this Timer class i wrote some time ago. An advantage is that it's "incremental" you can start a timer inside a loop, and it will append the time between start and stop.
Please note that if you do that, it will had quite some time to execution.
basic usage:
please note it's limited and far not the fastest way to do it. creating and destoying classes takes time. When done inside "logical" loops, it can add quite some time. but to trace some complex program with multiple imbricated loops, or recursive functions calls, this stuff is precious
如果你想以面向对象的方式来做,你可以上一堂课,从哪里开始。
我相信它是在 codeigniter 框架中完成的。
这些名称(“piece1”)的要点是您可以同时运行多个计时器(例如一个计时器在另一个计时器中运行)。实现ihg的代码相当简单,大约10行。
If you want to do it in a OO manner, you can have a class, where you start.
I believe it is done like that in codeigniter framework.
The point of these names ('piece1') is that you can have multiple timers running at the same time (example one in another). The code for implementihg is fairly simple, about 10 lines.