bonsaicode/timer

用于基准测试PHP代码的计时器实用类。

1.0.5 2019-08-19 05:20 UTC

This package is auto-updated.

Last update: 2024-09-19 16:21:28 UTC


README

计时器实用类。

  • 用于基准测试代码的计时器类。

要求

  • PHP 7.1或更高版本

安装

要在控制台安装模块,请运行以下命令

$ composer require "bonsaicode/timer"

使用

<?php
	# instantiating Timer automatically starts the timer unless you pass false to the constructor
	$timer = new BonsaiCode\Timer();
	
	# [ put code here that you want to time ]

	# get the elapsed time as a string, defaults to 8 decimal places
	echo 'Elapsed seconds: '.$timer->get()."\n";

	# restart the timer
	$timer->start();

	# [ put code here that you want to time ]

	# pause the timer
	$timer->pause();

	# [ code you don't want to time ]

	# resume the timer
	$timer->unpause();

	# show elapsed time since the last start, exclude all paused time
	echo 'Elapsed seconds: '.$timer->get()."\n";
?>

致谢

基于https://davidwalsh.name/php-timer-benchmark