<?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)
{
if ($point1 == '')
{
return '{elapsed_time}';
} if ( ! isset($this->marker[$point1]))
{
return '';
} if ( ! isset($this->marker[$point2]))
{
$this->marker[$point2] = microtime();
} 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 */

看了下源码,主要通过elapsed_time()函数计算二个时间点的时间间隔;通过

list($sm, $ss) = explode(' ', $this->marker[$point1]);
list($em, $es) = explode(' ', $this->marker[$point2]);
return number_format(($em + $es) - ($sm + $ss), $decimals);

方式返回时间间隔。

备注microtime() 当前 Unix 时间戳以及微秒数。本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自 Unix 纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec 是微秒部分。字符串的两部分都是以秒为单位返回的。

CI核心文件分析之基准测试类 (Benchmark.php)的更多相关文章

  1. Linux可信计算机制模块详细分析之核心文件分析(8)tpm.c核心代码注释(中)

    /*设置TPM命令格式*/ ssize_t tpm_getcap(struct device *dev, __be32 subcap_id, cap_t *cap, const char *desc) ...

  2. CI框架 -- 核心文件 之 Hooks.php

    钩子 - 扩展框架核心 CodeIgniter 的钩子特性提供了一种方法来修改框架的内部运作流程,而无需修改 核心文件.CodeIgniter 的运行遵循着一个特定的流程,你可以参考这个页面的 应用程 ...

  3. CI框架的引导流程以及基准测试类

    一[CI]框架的引导流程了解一下,并掌握如何新增自己的扩展类库   http://www.cnblogs.com/ohmygirl/p/CIRead-4.html // CI框架源码阅读笔记4 引导文 ...

  4. ThinkPHP6 核心分析之Http 类跟Request类的实例化

    以下源码分析,我们可以从 App,Http 类的实例化过程,了解类是如何实现自动实例化的,依赖注入是怎么实现的. 从入口文件出发 当访问一个 ThinkPHP 搭建的站点,框架最先是从入口文件开始的, ...

  5. 使用 Eclipse Memory Analyzer 进行堆转储文件分析

    Eclipse Memory Analyzer(MAT)是著名的跨平台集成开发环境 Eclipse Galileo 版本的 33 个组成项目中之一,它是一个功能丰富的 JAVA 堆转储文件分析工具,可 ...

  6. Nmap脚本文件分析(AMQP协议为例)

    Nmap脚本文件分析(AMQP协议为例) 一.介绍 上两篇文章 Nmap脚本引擎原理   编写自己的Nmap(NSE)脚本,分析了Nmap脚本引擎的执行过程,以及脚本文件的编写,这篇文章将以解析AMQ ...

  7. 分析业务模型-类图(Class Diagram)

    分析业务模型-类图(Class Diagram)     分析业务模型-类图(Class Diagram)(上) 摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并 ...

  8. mat 使用 分析 oom 使用 Eclipse Memory Analyzer 进行堆转储文件分析

    概述 对于大型 JAVA 应用程序来说,再精细的测试也难以堵住所有的漏洞,即便我们在测试阶段进行了大量卓有成效的工作,很多问题还是会在生产环境下暴露出来,并且很难在测试环境中进行重现.JVM 能够记录 ...

  9. [Android Memory] 使用 Eclipse Memory Analyzer 进行堆转储文件分析

    转载地址:http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-ma/index.html Eclipse Memory Analyzer ...

随机推荐

  1. ie下li标签中span加float:right不换行问题解决方案

    在IE6,IE7下使用标签时,在加入右浮动样式(float:right)后,会换行的bug解决方案:bug案例:新闻列表中,为使时间右对齐,加右浮动产生换行 <ul> <li> ...

  2. Linux下挂载指定分区下的某个文件夹到指定目录(mount)

    # 挂载 mount --bind olddir newdir # 卸载 umount newdir 参考: http://www.cnblogs.com/dabaopku/archive/2010/ ...

  3. 获取非行间样式getComputedStyle

    有如下代码: 1 2 3 div {     width: 200px; } 1 2 3 <div id="aa" style="height: 100px;&qu ...

  4. 45个非常有用的Oracle查询语句(转自开源中国社区)

    日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 “SYSDATE”来指定查询的日期. SELECT TRUNC (SYSDATE, 'MO ...

  5. C#应用程序配置文件.config介绍

    我们经常会希望在程序中写入一些配置信息,例如版本号,以及数据库的连接字符串等.你可能知道在WinForm应用程序中可以利用Properties.Settings来进行类似的工作,但这些其实都利用了Ap ...

  6. 【翻译自mos文章】当并行事务恢复进程在执行时,禁用并行事务恢复的方法

    当并行事务恢复进程在执行时,禁用并行事务恢复的方法 How to Disable Parallel Transaction Recovery When Parallel Txn Recovery is ...

  7. 配置mysql主从服务器

    参考:https://www.linuxidc.com/Linux/2016-09/135633.htm 一.Master主服务器配置(192.168.1.3) 1.编辑my.cnf(命令查找文件位置 ...

  8. 首先使用flex制作table

    HTML(JavaScript) <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  9. myeclipse2014破解

    去年出现的struts2 bug问题,在过去的项目中一直没做调整,前段时间发现受到影响了.本想这个bug都已经这么长时间了,工具中的包应该也已经被替换了吧,于是下载了最新的myeclipse2014, ...

  10. django(一)--- 安装django

    准备好虚拟环境:Python开发虚拟环境 安装前的准备 1. 下载django:django下载 本文使用的是django-1.5.9(不同版本号之间的差别还是比較大的.别搞错了) 2.准备djang ...