Download the PHP package christiaanbye/stopwatch without Composer

On this page you can find all versions of the php package christiaanbye/stopwatch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package stopwatch

Stopwatch

As the name implies, this is a helper for profiling code in PHP. The library is designed with the following in mind:

  1. Absolute minimal overhead. The reason you are reading this, is you likely have one or more short tasks to profile. Polluting the results by adding a few hundreds of a second in overhead, won't do anybody good.
  2. Drop-dead simple API. No decision-making in how the results should be presented or how to name the measuring instance. Just a simple start and stop with maybe a few laps in between. If you require more advanced features, in-code profiling might not be the most suitable approach for your use case.
  3. Maximum compatibility with older PHP versions. The most of us have had the joy of working with end-of-life PHP versions. Thankfully versioning exists, so one could install an older version of their library of choice. Unfortunately this sometimes does come at the expense of a subtly altered public API. I'd rather remove mental friction than add to it, so you can use the very same library with age-old PHP 5.6 all the way to modern-day PHP 8.

Prerequisites

Installation

Installation can be easily done using Composer:

Advanced users may advocate to add the --dev flag and rely on their quality gate to detect usages of the undefined Stopwatch class to prevent accidental production use.

Usage

For basic use, you can use the start(), stop() and elapsed() methods:

The elapsed() method returns a float of one of the following:

The latter can be useful if you wish to log the elapsed time further down execution.

In more advanced use cases, one can also make use of the split() method in conjunction with the getSplits() method. This allows you to record the intermediate time between tasks:

The getSplits() method returns all intermediates and the overall time as an array containing the following:

The result of the above code looks as follows:

Similarly to the elapsed() method, the stopwatch can be stopped prior to calling getSplits() so the recorded execution times are not affected by logging late during runtime.


All versions of stopwatch with dependencies

PHP Build Version
Package Version
Requires php Version ^5.4 || ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package christiaanbye/stopwatch contains the following files

Loading the files please wait ....