Izartu  0.0 Initial release
Web bookmark manager based on tags.
 All Data Structures Files Functions Variables Enumerations
Benchmark.php
Go to the documentation of this file.
00001 <?php
00002 #  Izartu
00003 #
00004 #  Copyright © 2011-2012 Javier Beaumont <contact@javierbeaumont.org>
00005 #
00006 #  This file is part of Izartu.
00007 #
00008 #  Izartu is free software: you can redistribute it and/or modify
00009 #  it under the terms of the GNU Affero General Public License as
00010 #  published by the Free Software Foundation, either version 3 of the
00011 #  License, or (at your option) any later version.
00012 #
00013 #  Izartu is distributed in the hope that it will be useful,
00014 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016 #  GNU Affero General Public License for more details.
00017 #
00018 #  You should have received a copy of the GNU Affero General Public License
00019 #  along with Izartu. If not, see <http://www.gnu.org/licenses/>.
00020 
00031 class Benchmark {
00032   private $timeStart;
00033   private $timeEnd;
00034   private $timeTotal;
00035   private $memoryStart;
00036   private $memoryEnd;
00037   private $memoryMax;
00038   private $memoryTotal;
00039   private $usage;
00040 
00046   final public function __construct() {
00047     $this->timeStart = microtime(TRUE);
00048     $this->memoryStart = memory_get_peak_usage();
00049   }
00050 
00057   final public function get() {
00058     $this->timeEnd = microtime(TRUE);
00059     $this->memoryEnd = memory_get_peak_usage();
00060     $this->memoryMax = memory_get_peak_usage(TRUE);
00061 
00062     $this->timeTotal = number_format(round(($this->timeEnd - $this->timeStart)*1000, 2), 2);
00063     $this->memoryTotal = number_format(round(($this->memoryEnd - $this->memoryStart)/1024, 2), 2);
00064     $this->memoryEnd = number_format(round($this->memoryEnd/1024, 2), 2);
00065     $this->memoryMax = number_format(round($this->memoryMax/1024, 2), 2);
00066 
00067     return '
00068       <dl id="debug">
00069         <dt class="time">Execution time:</dt>
00070         <dd>Time: ' . $this->timeTotal . ' ms.</dd>
00071         <dt class="memory">Memory usage:</dt>
00072         <dd>Max: ' . $this->memoryMax . ' KB.</dd>
00073         <dd>Used: ' . $this->memoryEnd . ' KB.</dd>
00074         <dd>Script: ' . $this->memoryTotal . ' KB.</dd>
00075       </dl>';
00076   }
00077 
00078 }
 All Data Structures Files Functions Variables Enumerations