jun3453/prosp

PHP 的处理速度测量库。

v0.0.3 2020-03-24 03:47 UTC

This package is auto-updated.

Last update: 2024-09-24 20:26:24 UTC


README

PHP 的处理速度测量库。

描述

我在 Google 上搜索了 "如何用 PHP 测量处理时间"。
我总是忘记如何做,所以我把这个功能做成了一个库。

在这个库中,你可以在处理过程中放置开始和结束调用,以毫秒为单位测量处理时间。

安装

$ composer require jun3453/prosp

用法

示例

for($i=0;$i<2;$i++) {
	ProcessingSpeedMeasurement::startProcessing("foo");
	/** Write foo processing */

	for($j=0;$j<2;$j++) {
		ProcessingSpeedMeasurement::startProcessing("bar");
		/** Write bar processing  */
		ProcessingSpeedMeasurement::endProcessing("bar");
	}

	ProcessingSpeedMeasurement::endProcessing("foo");
}

此结果已转换为毫秒。

获取指定上下文的结果。

ProcessingSpeedMeasurement::getProcessingResultByContext("foo")

array(2) {
  'processTimes' =>
  array(2) {
    [1] =>
    double(0.43487548828125)
    [2] =>
    double(0.08082389831543)
  }
  'totalRounds' =>
  int(2)
}

获取所有上下文结果。

ProcessingSpeedMeasurement::getAllProcessingResults()

array(2) {
  'bar' =>
  array(2) {
    'processTimes' =>
    array(4) {
      [1] =>
      double(0.042915344238281)
      [2] =>
      double(0.25415420532227)
      [3] =>
      double(0.016927719116211)
      [4] =>
      double(0.016927719116211)
    }
    'totalRounds' =>
    int(4)
  }
  'foo' =>
  array(2) {
    'processTimes' =>
    array(2) {
      [1] =>
      double(0.43487548828125)
      [2] =>
      double(0.08082389831543)
    }
    'totalRounds' =>
    int(2)
  }
}

获取所有超过指定毫秒的上下文。

ProcessingSpeedMeasurement::getResultsLongerThanSpecifiedMs(0.04)

array(2) {
  'bar' =>
  array(2) {
    [0] =>
    array(2) {
      'processTime' =>
      double(0.042915344238281)
      'round' =>
      int(1)
    }
    [1] =>
    array(2) {
      'processTime' =>
      double(0.25415420532227)
      'round' =>
      int(2)
    }
  }
  'foo' =>
  array(2) {
    [0] =>
    array(2) {
      'processTime' =>
      double(0.43487548828125)
      'round' =>
      int(1)
    }
    [1] =>
    array(2) {
      'processTime' =>
      double(0.08082389831543)
      'round' =>
      int(2)
    }
  }
}