Maison php教程 php手册 使用xhprof在开发环境中测试php性能

使用xhprof在开发环境中测试php性能

Jun 02, 2016 am 09:13 AM
include

XHProf是一个分层PHP性能分析工具。它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况。现在我们来聊聊XHProf在开发环境中如何测试php性能。

以百分之一的概率产生测试数据,尽量不影响正式环境效率。

class XHProf {
    // private $XHProfPath = 'xhprof/';
    private $XHProfPath = '/usr/local/apache/htdocs/xhprof/';
    private $applicationName = 'sias_application';
    private $sampleSize = 100;
    private static $enabled = false;
    public function XHProf_Start() {
        if (mt_rand(1, $this->sampleSize) == 1) {
            include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_lib.php';
            include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_runs.php';
            xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
            self::$enabled = true;
        }
    }
    public function XHProf_End() {
        if (self::$enabled) {
            $XHProfData = xhprof_disable();
            $XHProfRuns = new XHProfRuns_Default();
            $XHProfRuns->save_run($XHProfData, $this->applicationName);
        }
    }
}
Copier après la connexion

测试效果:

Overall Summary     
Total Incl. Wall Time (microsec):     48,162 microsecs
Total Incl. CPU (microsecs):     32,994 microsecs
Total Incl. MemUse (bytes):     2,773,464 bytes
Total Incl. PeakMemUse (bytes):     2,867,664 bytes
Number of Function Calls:     749
Copier après la connexion

使用xhprof在开发环境中测试php性能

使用xhprof在开发环境中测试php性能

从以下测试结果看出,耗时最多的居然是连接数据库,所以我们来尽量优化数据库。

本文地址:

转载随意,但请附上文章地址:-)

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

Video Face Swap

Video Face Swap

Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)