shmeeps/simple-timer

为PHP应用程序计时/基准测试提供的简单界面

dev-master / 1.1.x-dev 2016-10-27 05:18 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:42:05 UTC


README

用于跟踪PHP脚本执行时间的简单计时器

使用方法

<?php

use Shmeeps\SimpleTimer\SimpleTimer;

class Foo
{
    public function doSomething()
    {
		// ---- Single tracking
	
		// Start the timer
        SimpleTimer::start("formatLoop");
		
		// Execute code
		foreach ($this->objects as $object) {
			$object->format();
		}
		
		// Stop the timer
		SimpleTimer::stop("formatLoop");
		
		// Output the total time spent in the loop
		var_dump(SimpleTimer::getTotalTime("formatLoop"));
		
		// ---- Multiple tracking
		
		// Execute code
		foreach ($this->objects as $object) {
		
			SimpleTimer::start("fetchData");
			$object->fetch();
			SimpleTimer::stop("fetchData");
			
			SimpleTimer::start("prepData");
			$object->prep();
			SimpleTimer::stop("prepData");
			
			SimpleTimer::start("formatData");
			$object->format();
			SimpleTimer::stop("formatData");
		}
		
		// Output the total time fetching, the average time prepping, and both for formatting
		var_dump(SimpleTimer::getTotalTime("fetchData"));
		var_dump(SimpleTimer::getAverageTime("preData"));
		var_dump(SimpleTimer::getRawTime("formatData"));
    }
}