stm32 基准计时器_PHP优化–使用计时器对代码进行基准测试并提高速度

stm32 基准计时器

One of the best parts about being a programmer is that there's seemingly always a better way to do things. A simple code tweak can drastically improve the execution time of your web application. The faster your application executes the quicker you release precious server resources.

成为程序员最好的部分之一是,似乎总是有一种更好的做事方式。 简单的代码调整可以极大地缩短Web应用程序的执行时间。 应用程序执行得越快,释放宝贵的服务器资源的速度就越快。

The first step in optimizing your existing PHP-based web application for speed is knowing which portions of your website need to be improved. Do your MySQL queries take too long? Are you using efficient functions? Are you using unnecessary server resources?

优化现有基于PHP的Web应用程序以提高速度的第一步是知道网站的哪些部分需要改进。 您MySQL查询时间是否太长? 您是否在使用高效功能? 您是否在使用不必要的服务器资源?

In my web applications I use a timer class to benchmark how long queries, functions, and entire pages are taking to complete.

在我的Web应用程序中,我使用计时器类来基准化查询,函数和整个页面花费的时间。

功能 (The Function)

class timer {
	var $start;
	var $pause_time;

	/*  start the timer  */
	function timer($start = 0) {
		if($start) { $this->start(); }
	}

	/*  start the timer  */
	function start() {
		$this->start = $this->get_time();
		$this->pause_time = 0;
	}

	/*  pause the timer  */
	function pause() {
		$this->pause_time = $this->get_time();
	}

	/*  unpause the timer  */
	function unpause() {
		$this->start += ($this->get_time() - $this->pause_time);
		$this->pause_time = 0;
	}

	/*  get the current timer value  */
	function get($decimals = 8) {
		return round(($this->get_time() - $this->start),$decimals);
	}

	/*  format the time in seconds  */
	function get_time() {
		list($usec,$sec) = explode(' ', microtime());
		return ((float)$usec + (float)$sec);
	}
}

用法 (The Usage)

$timer = new timer(1); // constructor starts the timer, so no need to do it ourselves
/*

 ... mysql query ...

*/
$query_time = $timer->get();
/*

 ... page processing ...

*/
$processing_time = $timer->get();

输出 (The Output)

Once you know which areas of your website need improvement, making your code more efficient can be easy if you're code is well-commented and organized. Use the timer -- which areas of your website did you notice needed improvement and how did you optimize the code? I'd love to hear your problems and solutions!

一旦知道了网站的哪些方面需要改进,就可以轻松地提高代码效率(如果您对代码进行了很好的注释和组织)。 使用计时器-您注意到网站的哪些方面需要改进,以及如何优化代码? 我希望听到您的问题和解决方案!

翻译自: https://davidwalsh.name/php-timer-benchmark

stm32 基准计时器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值