Download the PHP package flaviovs/timeit without Composer

On this page you can find all versions of the php package flaviovs/timeit. 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 timeit

Library and tools to measure execution speed of PHP code

Introduction

This package contain a library and tools to measure execution speed of PHP code. You can use it to measure alternative code when profiling and improving performance of your application.

Requirements

This package requires PHP 5.4 or above.

How to use

You should require src/Timer.php in your PHP script to use the object-oriented interface. A procedural interface is also available -- to use it, require src/functions.php.

Basic usage

To get timings of code runs, use the code below:

$timer = new \TimeIt\Timer('pow(2, 5)');
$res = $timer->timeit();

The returned $res variable contains a three-elements array with the following information:

As said above, the object will calculate the number of rounds to return appropriate values, depending on the speed of your code (starting at 10 iterations). However, you can force it to use any number of rounds. To do this, pass the desired number to the timeit() method:

 $res = $timer->timeit(500);

You can make the object run the code several times, and return an array of results. To do this, call the repeat() method:

 $multi_res = $timer->repeat(500, 5);

This will call timeit(500) five times. In the example above, the returned value will be a multi-dimensional five-elements array containing the result of each run. The array of results will be sorted by execution speed in ascending order (i.e., highest execution speed first). The number of repetitions is optional. The default is 3.

Reference

Procedural interface

The library also provide a convenient procedural interface:

Command line script

The bin/timeit script provides a convenient interface to check execution speed of PHP code from the command line. Run the script passing PHP code as parameters. You can can pass many parameters in the same run, which make the script a very convenient way to help select which code perform best.

Example:

$ bin/timeit 'pow(5, 5)'
pow(5, 5): 100000 loops, best of 3: 9.21us per loop

$ bin/timeit 'pow(2, 5)' '2 * 2 * 2 * 2 * 2'
pow(2, 5): 100000 loops, best of 3: 8.51us per loop
2 * 2 * 2 * 2 * 2: 1000000 loops, best of 3: 4.10us per loop

Warning: you must be extra careful when passing PHP code in the command line to the timeit script, because single/double quotes -- very often used in PHP code -- may clash with the ones expected by your shell. The script expect that each separate shell parameter contains a single piece of code, but if you do not escape your quotes properly, the shell may divide the parameter in unexpected ways. You probably need to escape dollar signs as well, to prevent them to be interpreted by the shell.

Examples:

Wrong

$ bin/timeit '$a = 'foobar'; substr($a, 0, 1)'
PHP Notice:  Use of undefined constant foobar - assumed 'foobar' in /home/flaviovs/github/timeit/src/Timer.php(39) : eval()'d code on line 1
PHP Stack trace:
(...several errors...)

Right

$ bin/timeit '$a = "foobar"; substr($a, 0, 1)'

or

$ bin/timeit "\$a = 'foobar'; substr(\$a, 0, 1)" # We must escape the "$"

Caveat

This library measure the wall clock time needed to run code. This mean that different computers, different CPUs, or even different execution environments may affect measurements.

For instance, you should not expect to get the same numbers when measuring on two different computers, nor if you do measurements on the same computer at different times. For example, measuring the same code on a server under heavy I/O and in quiet times will probably not give you the same results.

Legal

Copyright 2015-2016 Flávio Veloso

This package is licensed under the Apache License version 2.0. See the file LICENSE for more details.

If you find bugs in this software, please open an issue on GitHub at https://github.com/flaviovs/timeit, or send it to me at flaviovs at magnux dot com.


All versions of timeit with dependencies

PHP Build Version
Package Version
Requires php Version >= 5.4
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 flaviovs/timeit contains the following files

Loading the files please wait ....