CI框架源码翻阅-基准测试类Benchmark.php
CI框架源码阅读---------基准测试类Benchmark.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------ /** * CodeIgniter Benchmark Class * * This class enables 能够 you to mark points and calculate 计算 the time difference 差异 * between them. Memory consumption can also be displayed. * * @package CodeIgniter * @subpackage Libraries * @category Libraries * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/benchmark.html */ class CI_Benchmark { /** * List of all benchmark markers and when they were added * 用来存储基准测试类标记的数组 * @var array */ var $marker = array(); // -------------------------------- /** * Set a benchmark marker * 设置一个标记点 * Multiple calls to this function can be made so that several * execution points can be timed * * @access public * @param string $name name of the marker * @return void */ function mark($name) { // 在程序的任意地方调用方法时,会记录当前的时间点。 $this->marker[$name] = microtime(); } // -------------------------------- /** * Calculates the time difference between two marked points. * 计算出两个时间点之间的时间。 * If the first parameter is empty this function instead returns the * {elapsed_time} pseudo-variable 虚假变量. This permits 许可 the full system * execution time to be shown in a template. The output class will * swap the real value for this variable. * * @access public * @param string a particular marked point * @param string a particular marked point * @param integer the number of decimal places * @return mixed */ function elapsed_time($point1 = '', $point2 = '', $decimals = 4) { /* * 如果没有给出明确的时间点,那么会计算出整个程序运行的时间。 * 怎么可以做到计算出整个程序的运行时间的呢?其实执行此计算的是Output组件。 * 而调用Benchmark::elapsed_time();(无参数)的时候,实质上先返回的并不是 * 整个程序运行的时间,也不可能做到,实质返回的是一个{elapsed_time}标签,然后 * Output在处理输出的时候,再计算出整个程序运行时间,因为处理输出阶段程序可以视 * 为处于最后阶段,于是可以近似计算出总时间,然后把输出中的{elapsed_time}替换掉。 * 下面的memory_usage()原理相同。 */ if ($point1 == '') { return '{elapsed_time}'; } if ( ! isset($this->marker[$point1])) { return ''; } if ( ! isset($this->marker[$point2])) { $this->marker[$point2] = microtime(); } //这里为什么要用到list,是因为microtime();返回值是“msec sec”的格式。 list($sm, $ss) = explode(' ', $this->marker[$point1]); list($em, $es) = explode(' ', $this->marker[$point2]); return number_format(($em + $es) - ($sm + $ss), $decimals); } // -------------------------------- /** * Memory Usage * * This function returns the {memory_usage} pseudo-variable. * This permits it to be put it anywhere in a template * without the memory being calculated until the end. * The output class will swap the real value for this variable. * * @access public * @return string */ function memory_usage() { return '{memory_usage}'; } } // END CI_Benchmark class /* End of file Benchmark.php */ /* Location: ./system/core/Benchmark.php */

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

如何在CodeIgniter中實現自訂中間件引言:在現代的Web開發中,中間件在應用程式中起著至關重要的作用。它們可以用來執行在請求到達控制器之前或之後執行一些共享的處理邏輯。 CodeIgniter作為一個流行的PHP框架,也支持中間件的使用。本文將介紹如何在CodeIgniter中實作自訂中間件,並提供一個簡單的程式碼範例。中間件概述:中間件是一種在請求

CodeIgniter中間件:加速應用程式的反應速度和頁面渲染概述:隨著網頁應用程式的複雜性和互動性不斷增長,開發人員需要使用更有效率和可擴展的解決方案來提高應用程式的效能和反應速度。 CodeIgniter(CI)是一種基於PHP的輕量級框架,提供了許多有用的功能,其中之一就是中間件。中間件是在請求到達控制器之前或之後執行的一系列任務。這篇文章將介紹如何使用

在CodeIgniter框架中使用資料庫查詢建構器(QueryBuilder)的方法引言:CodeIgniter是一個輕量級的PHP框架,它提供了許多功能強大的工具和函式庫,方便開發人員進行Web應用程式開發。其中一個令人印象深刻的功能是資料庫查詢建構器(QueryBuilder),它提供了一種簡潔而強大的方法來建立和執行資料庫查詢語句。本文將介紹如何在Co

隨著行動互聯網的發展,即時通訊變得越來越重要,越來越普及。對許多企業而言,即時聊天更像是一種通訊服務,提供便利的溝通方式,可以快速有效地解決業務方面的問題。基於此,本文將介紹如何使用PHP框架CodeIgniter開發一個即時聊天應用程式。了解CodeIgniter框架CodeIgniter是一個輕量級的PHP框架,提供了一系列的簡單的工具和函式庫,幫助開發者快速

隨著Web應用程式的不斷發展,更加快速和有效率地開發應用程式變得非常重要。並且,隨著RESTfulAPI在網路應用程式中的廣泛應用,對於開發人員來說,必須理解如何建立和實作RESTfulAPI。在本文中,我們將討論如何使用CodeIgniter框架實現MVC模式和RESTfulAPI。 MVC模式簡介MVC(Model-Vie

CodeIgniter中間件:提供安全的檔案上傳和下載功能引言:在網路應用程式開發過程中,檔案上傳和下載是非常常見的功能。然而,對於安全性的考慮,處理文件上傳和下載通常需要額外的安全措施。 CodeIgniter是一個流行的PHP框架,提供了豐富的工具和函式庫來支援開發者建立安全可靠的網路應用程式。本文將介紹如何使用CodeIgniter中介軟體來實現安全的文件

CodeIgniter是一個輕量級的PHP框架,採用MVC架構,支援快速開發和簡化常見任務。 CodeIgniter5是該框架的最新版本,提供了許多新的功能和改進。本文將介紹如何使用CodeIgniter5框架來建立一個簡單的Web應用程式。步驟1:安裝CodeIgniter5下載和安裝CodeIgniter5非常簡單,只需要遵循以下步驟:下載最新版本

現今網路時代,一款深受使用者喜愛的網站必須具備簡潔明了的前端介面和功能強大的後台管理系統,而PHP框架CodeIgniter則是一款能夠讓開發者快速搭建後台管理系統的優秀框架。 CodeIgniter擁有輕量級、高效率、易擴展等特點,本文將針對初學者,詳細說明如何透過該框架快速建立一個後台管理系統。一、安裝配置安裝PHPCodeIgniter是一個基於PHP的
