2017 © Pedro Peláez
 

library profiling

Profiling library for PHP 5.6+

image

irap/profiling

Profiling library for PHP 5.6+

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 12 % Grown

The README.md

package-profiling

This is a package for PHP which makes it easier to find which functions/areas take the most time., (*1)

Installation

Install through composer with:, (*2)

composer require irap/profiling

Usage

Below is an example script that demonstrates using this tool:, (*3)

<?php

# Include the autoloader for packages.
require_once(__DIR__ . '/vendor/autoload.php');

function Bar()
{
    \iRAP\Profiling\FunctionAnalyzer::start();
    sleep(3);
    \iRAP\Profiling\FunctionAnalyzer::stop();
}

function Foo()
{
    \iRAP\Profiling\FunctionAnalyzer::start();
    sleep(1);
    Bar();
    \iRAP\Profiling\FunctionAnalyzer::stop();
}

Foo();
print \iRAP\Profiling\FunctionAnalyzer::getResults();

This should output something similar to:, (*4)

Foo: 1.0001013278961 seconds
Bar: 3.0002498626709 seconds

Notice that even though Bar is called from within Foo, so Foo takes a total of 4 seconds to execute, the result for Foo is just 1 second because the tool is showing how much time was taken up doing logic in Foo rather than within Bar because Bar is already being profiled separately. If you wanted the total time taken within Foo including Bar, then one just needs to take the analyzer calls out of the Bar method:, (*5)

<?php

# Include the autoloader for packages.
require_once(__DIR__ . '/vendor/autoload.php');

function Bar()
{
    sleep(3);
}

function Foo()
{
    \iRAP\Profiling\FunctionAnalyzer::start();
    sleep(1);
    Bar();
    \iRAP\Profiling\FunctionAnalyzer::stop();
}

Foo();
print \iRAP\Profiling\FunctionAnalyzer::getResults();

Output:, (*6)

Foo: 4.0003681182861 seconds

Profiling Small Sections - Custom Names

If you have a very long function, and want to profile separate parts of it, then you can just provide a custom name to the start and stop methods like so:, (*7)

require_once(__DIR__ . '/vendor/autoload.php');

function Bar() { sleep(3); }
function Foo() { sleep(1); }

function main()
{
    \iRAP\Profiling\FunctionAnalyzer::start('part1');
    Foo();
    \iRAP\Profiling\FunctionAnalyzer::stop('part1');

    // Profiling part 2
    \iRAP\Profiling\FunctionAnalyzer::start('part2');
    Bar();
    Foo();
    \iRAP\Profiling\FunctionAnalyzer::stop('part2');
}

main();
print \iRAP\Profiling\FunctionAnalyzer::getResults();

... which outputs:, (*8)

part1: 1.0000782012939 seconds
part2: 4.0001401901245 seconds

The Versions

12/06 2018

dev-master

9999999-dev https://github.com/iRAP-software/package-profiling

Profiling library for PHP 5.6+

  Sources   Download

MIT None

The Requires

  • php >=5.6.0

 

library profiling

12/06 2018

1.0.1

1.0.1.0 https://github.com/iRAP-software/package-profiling

Profiling library for PHP 5.6+

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

profiling

21/07 2017

1.0.0

1.0.0.0 http://www.irap.org

Profiling library for PHP 5.6+

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

profiling