Acumen Development

  • Acumen Development
  • Acumen Systems
  • Acumen Third Sector
  • About Us
  • Websites
  • Web Applications
  • Branding
  • Support
  • Contact Us

PHP StopWatch Class

recent news

  • Wordpress and Subversion
    Leo Brown, 1st June

  • Working with Corrupt Subversion Repositories
    Leo Brown, 20th January

  • Integrating with Web1.0 Service Providers
    Leo Brown, 4th June

  • WordPress Text Replacement Plugin
    Leo Brown, 14th February

  • Direct Email Reception
    Leo Brown, 2nd January

Project Request Form

Download a project request form here

PHP StopWatch Class

April 16, 2008
categories: Open Source
tags: debugging, performance, stopwatch

Just a simple little class to play around with. I quickly threw it together because I got fed up of writing performance debugging code into perfectly clean classes, and then having to strip it out again later. The stop watch allows you to set callback methods to receive any calls to the stopwatches mark method, which as it’s a singleton can be called just about anywhere. Additionally it uses sprintf() strings to format the message and time.

Additionally this shows how in two lines you can be notified of the scripts entire execution time using StopWatch.

<?php
include('StopWatch.class.php');
$stopWatch=StopWatch::getInstance();
$stopWatch-&amp;amp;gt;setFinishMessage('script executed in %01.2f seconds');
sleep(2);
?>

And here’s the source stopwatch.zip.