Download the PHP package codon/profiler without Composer
On this page you can find all versions of the php package codon/profiler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codon/profiler
More information about codon/profiler
Files in codon/profiler
Package profiler
Short Description A PHP 5.4+ profiling/benchmarking tool
License MIT
Homepage https://github.com/nshahzad/codon-profiler
Informations about the package profiler
Codon/Profiler
A PHP 5.4+ profiling class, loosely based on the PEAR Benchmark package.
- Author: Nabeel Shahzad [email protected]
- Homepage: http://nshahzad.github.com/codon-profiler/
- Github: https://github.com/nshahzad/codon-profiler
- Packagist: http://packagist.org/packages/codon/profiler
- License: MIT
- Version: 1.0
Current to-do list:
- Console colors to show the fastest test runs
- Show percentage differences between runs
- Use the Vulcan Logic Dumper (http://derickrethans.nl/projects.html#vld) to allow you to see opcode differences
Installation
Add to your composer.json file:
Then run the composer update
Basic Usage
This class extensively uses closures, and all of the methods (except for getResults) are chainable. Declare a new Profiler class:
Which will output something like:
Settings
To change profiler settings, use the function:
Some settings (type and (default)):
- showOutput - bool (false)- supress output from the test runs
- tareRuns - bool (true) - There is some penalty for running a closure. This will average the time to run an empty closure, and subtract it from the average of all the runs (only from the total, not checkpoints or timers that are called within)
- formatMemoryUsage - bool (true) - Show the memory usage in a digestable format
Using the Profiler
There are two ways you can use the profile:
- Add tests using ; (see test/benchmark.php)
- Profile code inline using the ; (see test/inline.php)
add()
To add a test, you use the method, which accepts an array of:
This method can be chained
Tip: To use checkpoints/timers and other functionality within your test run, pass the Profiler object via (as a reference). You can also pass any other data/variables needed for your tests via the
run()
To run all of the tests, call :
Passing parameters
Your test function can also have any parameters, and any parameters passed to will be passed to the closure. I.e, if you're measuring run-times of methods in a class:
clear()
Use the function to clear the results of previous tests.
clearAll()
Use the function to reset the profiler to having no tests or runs.
startTimer($name)/endTimer($name)
To measure points within a running benchmark. Can also be used inline (see below)
- $name Name of the timer
checkpoint($name)
Mark a checkpoint time from the start of the current test
- $name Checkpoint name
markMemoryUsage($name)
This will take note of a memory usage at the point that this is called. Gets the usage by the script, PHP engine, and peak usage.
- $name Name of the current point
showResults($html = false, $return = false)
Shows a formatted table
- $html If not false, will return
instead of newlines, and put it in atag with the class name of what's passed
- $return To return the results as a string, or just echo it out right away
getResults()
Returns an array with the raw results of a run
Using the profiler inline
You can call the and functions in any inline code.
Which shows:
Examples
Measuring two ways of doing a for() loop:
Showing:
Using Timers and checkpoints
Which will output: