Ignore:
Timestamp:
Apr 13, 2006 12:00:40 AM (18 years ago)
Author:
scdev
Message:

Q - Complete rebuild of PEdit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/ScriptTimer.inc.php

    r91 r92  
    11<?php
    22/**
    3  * ScriptTimer.inc.php
     3 * ScriptTimer.inc.php 
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    55 */
    6 
     6 
    77class ScriptTimer {
    88
    9     var $time_format = '%.10f';
    10     var $_timing_start_times;
    11     var $_timing_stop_times;
    12 
    13     function start($name='default')
    14     {
     9    var $time_format = '%.10s';
     10    var $_timing_start_times = array();
     11    var $_timing_stop_times = array();
     12    var $_timing_cumulative_times = array();
     13   
     14    function start($name='default')
     15    {
    1516        $this->_timing_start_times[$name] = explode(' ', microtime());
    16     }
    17 
    18     function stop($name='default')
    19     {
     17    }
     18   
     19    function stop($name='default')
     20    {
    2021        $this->_timing_stop_times[$name] = explode(' ', microtime());
    21     }
    22 
    23     function getTime($name='default')
    24     {
     22        $this->_timing_cumulative_times[$name] += $this->getTime($name);
     23    }
     24   
     25    function getTime($name='default')
     26    {
    2527        if (!isset($this->_timing_start_times[$name])) {
    2628            return 0;
    2729        }
    28 
    2930        if (!isset($this->_timing_stop_times[$name])) {
    3031            $stop_time = explode(' ', microtime());
     
    3233            $stop_time = $this->_timing_stop_times[$name];
    3334        }
    34 
    3535        // Do the big numbers first so the small ones aren't lost.
    3636        $current = $stop_time[1] - $this->_timing_start_times[$name][1];
    3737        $current += $stop_time[0] - $this->_timing_start_times[$name][0];
     38        return $current;
     39    }
     40   
     41    function printAll($sort_by_time=false)
     42    {
     43        $names = array_map('strlen', array_keys($this->_timing_start_times));
     44        sort($names);
     45        $name_len = end($names);
     46       
     47        if ($sort_by_time) {
     48           arsort($this->_timing_cumulative_times, SORT_NUMERIC);
     49        }
     50       
     51        $this->_timing_cumulative_times["TOTAL"] = array_sum($this->_timing_cumulative_times);
    3852
    39         return sprintf($this->time_format, $current);
    40     }
     53        echo '<pre>';
     54        foreach ($this->_timing_cumulative_times as $name => $time) {
     55            printf("\n%-{$name_len}s $this->time_format", $name, $time);
     56        }
     57        echo '</pre>';
     58    }
    4159}
    4260
Note: See TracChangeset for help on using the changeset viewer.