5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPで処理時間を計測

5
Posted at

ベンチマーク(Benchmark_Timer)

ベンチマークというよりも自分の場合は処理時間の計測によく使います。
計測の時にはこのコードを使うのだけど調査が終わるとコードから消してしまうことが多いので計りたいときに毎回どうやって書くかライブラリの中を調べているのでここにφ(.. )メモメモ

インストール

debian

# apt-get -y install php5 php-pear

centos

# yum  -y install php5 php-pear

pear

# pear install Benchmark

サンプルコード

APIなどのサーバーでは画面にでると良くないのでログに出力する場合。

require_once("Benchmark/Timer.php");
$timer = new \Benchmark_Timer(TRUE);

  :
(処理)
  :

$timer->stop();
error_log($timer->getOutput(true,'plain'));

通常のウェブサイトであれば結果として出力

<?php
require_once("Benchmark/Timer.php");
$timer = new \Benchmark_Timer();
$timer->start();
$timer->setMarker("step1"); 
$timer->setMarker("step2");
$timer->setMarker("step3");
$timer->stop();
$timer->display();

実行するとこんな感じ
img01.png

参考サイト

Benchmark_Timer

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?