Lost Password?


  #1 (permalink)  
Old 09-08-2007, 03:10 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,478
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default PHP: Timer Class

PHP Code:
<?php
/**
 * This class allows a user to to determine execution 
 * time of code blocks.
 *
 * @author John Ciacia <Sidewinder@extreme-hq.com>
 * @version 1.0
 * @copyright Copyright (c) 2007, John Ciacia
 * @license [url=http://opensource.org/licenses/gpl-license.php]Open Source Initiative OSI - The GPL:Licensing | Open Source Initiative[/url] GNU Public License
 */ 
 
class Timer {
    var 
$starttime   0;
    var 
$endtime     0;
    var 
$elapsed     0;
    var 
$timername   "Not Named";
    
    public function 
__construct() {

    }
    
    public function 
start() {
        
$this->starttime $this->_time();
    }
    
    public function 
stop() {
        
$this->endtime $this->_time();
        
$this->_compute();    
    }
    
    public function 
clear() {
        
$this->starttime   0;
        
$this->endtime     0;
        
$this->elapsed     0;
        
$this->timername   "Not Named";
    }
    
    public function 
elapsed() {
        return 
$this->elapsed;
    }
    
    public function 
settimername($name) {
        
$this->timername $name;
    }
    
    public function 
gettimername() {
        return 
$this->timername;
    }
    
    private function 
_time() {
        
$mtime microtime(); 
        
$mtime explode(' '$mtime); 
        
$mtime $mtime[1] + $mtime[0]; 
        return 
$mtime
    }
    
    private function 
_compute() {
        
$this->elapsed = (($this->endtime) - ($this->starttime));
    }


}

?>
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall

Last edited by John; 08-11-2008 at 07:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-08-2007, 04:04 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It looks really good, though I'm not able to try your code out. For some reason EasyPHP don't support public- and private-declarations.

I've some small suggestions to your code. Now when you're working with a class, then why don't you encapsulate $starttime, $endtime, $elapsed and $timername? This would give your code a better design, and the user will not be able to reach the variables directly, they've to use the functions. Beside that, you usually don't initialize the variables where you're doing it. It's done in the constructor (__construct())
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-17-2007, 03:13 PM
mgob mgob is offline
Newbie
 
Join Date: Sep 2007
Posts: 1
Rep Power: 0
mgob is on a distinguished road
Default

Very nice, I've got this working flawlessly
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-17-2007, 11:24 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,478
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

I'm glad you could make use of it. Just out of curiosity - what did you use it for?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Upload Class John PHP Tutorials 8 10-12-2008 09:06 PM
PHP 4 end of life announcement Jordan Programming News 4 08-30-2007 10:55 AM


All times are GMT -5. The time now is 08:32 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads