{"id":43479673,"url":"https://github.com/rotexsoft/callable-execution-timer","last_synced_at":"2026-02-03T08:14:11.677Z","repository":{"id":62537464,"uuid":"367205258","full_name":"rotexsoft/callable-execution-timer","owner":"rotexsoft","description":"A simple PHP library for tracking the total amount of time a callable (e.g. function / method) takes to execute and return result(s) (if any).","archived":false,"fork":false,"pushed_at":"2026-01-23T04:57:11.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-23T10:36:10.443Z","etag":null,"topics":["benchmark","benchmarking","callable","debug","measurement","performance","php","php-benchmark","php-callable","php-callback","php-debug","php-executor","php-functions","php-measurement","php-performance","php-profiler","php-profiling","php-timer","profiler","profiling"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rotexsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-05-14T00:14:00.000Z","updated_at":"2026-01-23T04:57:15.000Z","dependencies_parsed_at":"2024-03-15T19:49:48.243Z","dependency_job_id":"3c9f85f1-d226-4516-897d-1a496a9ad06a","html_url":"https://github.com/rotexsoft/callable-execution-timer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/rotexsoft/callable-execution-timer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rotexsoft%2Fcallable-execution-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rotexsoft%2Fcallable-execution-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rotexsoft%2Fcallable-execution-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rotexsoft%2Fcallable-execution-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rotexsoft","download_url":"https://codeload.github.com/rotexsoft/callable-execution-timer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rotexsoft%2Fcallable-execution-timer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29038066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T06:39:36.383Z","status":"ssl_error","status_checked_at":"2026-02-03T06:39:32.787Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","benchmarking","callable","debug","measurement","performance","php","php-benchmark","php-callable","php-callback","php-debug","php-executor","php-functions","php-measurement","php-performance","php-profiler","php-profiling","php-timer","profiler","profiling"],"created_at":"2026-02-03T08:14:10.916Z","updated_at":"2026-02-03T08:14:11.668Z","avatar_url":"https://github.com/rotexsoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Callable Execution Timer\n\n[![Run PHP Tests and Code Quality Tools](https://github.com/rotexsoft/callable-execution-timer/actions/workflows/php.yml/badge.svg)](https://github.com/rotexsoft/callable-execution-timer/actions/workflows/php.yml) \u0026nbsp;\n[![Release](https://img.shields.io/github/release/rotexsoft/callable-execution-timer.png?style=flat-square)](https://github.com/rotexsoft/callable-execution-timer/releases/latest) \u0026nbsp; \n[![License](https://img.shields.io/badge/license-BSD-brightgreen.png?style=flat-square)](https://github.com/rotexsoft/callable-execution-timer/blob/master/LICENSE) \u0026nbsp; \n[![Coverage Status](https://coveralls.io/repos/github/rotexsoft/callable-execution-timer/badge.svg?branch=main)](https://coveralls.io/github/rotexsoft/callable-execution-timer?branch=main) \u0026nbsp; \n![GitHub repo size](https://img.shields.io/github/repo-size/rotexsoft/callable-execution-timer) \u0026nbsp; \n![Packagist Downloads](https://img.shields.io/packagist/dt/rotexsoft/callable-execution-timer)\n![GitHub top language](https://img.shields.io/github/languages/top/rotexsoft/callable-execution-timer) \u0026nbsp; \n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/rotexsoft/callable-execution-timer) \u0026nbsp; \n![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/rotexsoft/callable-execution-timer/latest) \u0026nbsp; \n![GitHub last commit](https://img.shields.io/github/last-commit/rotexsoft/callable-execution-timer) \u0026nbsp; \n![GitHub Release Date](https://img.shields.io/github/release-date/rotexsoft/callable-execution-timer) \u0026nbsp; \n\u003ca href=\"https://libraries.io/packagist/rotexsoft%2Fcallable-execution-timer\"\u003e\n    \u003cimg alt=\"Libraries.io dependency status for GitHub repo\" src=\"https://img.shields.io/librariesio/github/rotexsoft/callable-execution-timer\"\u003e\n\u003c/a\u003e\n\n\nA simple PHP library for tracking the total amount of time a \n[callable](https://www.php.net/manual/en/language.types.callable.php) (e.g. \nfunction / method) takes to execute (it can also return the result of executing \nthe callable, if desired).\n\nIf you want to do some simple execution time profiling in your application, without using some full blown tool like debugbar or xdebug, then this is the package for you.\n\n\n## Installation \n\n**Via composer:** (Requires PHP 7.4+ or PHP 8.0+). \n\n    composer require rotexsoft/callable-execution-timer\n\n## Branching\n\nThese are the branches in this repository:\n\n- **main:** contains code for the latest major version of this package\n- **1.x:** contains code for the **1.x** version of this package\n- **2.x:** contains code for the **1.x** version of this package\n\n## Introduction\n\nA simple PHP library for tracking the total amount of time a callable (e.g. \nfunction / method) takes to execute and return result(s) (if any).\n\n\u003e For the rest of this documentation the term **callable** will mostly be referring to functions / methods\n\nThis library also provides information associated with each execution / invocation of the callable such as:\n\n* the arguments passed to the callable (array)\n* the total time it took to execute the callable in seconds (int / float)\n* the value returned from calling the callable (mixed)\n* the absolute path to the file in which the callable was called (string)\n* the exact line number in the file in which the callable was called (integer)\n\n## Executing callables\n\n### Executing built-in php functions\n\nLet's call php's built-in [strtolower](https://www.php.net/manual/en/function.strtolower.php) \u0026 [strtoupper](https://www.php.net/manual/en/function.strtoupper.php) functions:\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\necho CallableExecutionTimer::callFunc('strtolower', 'strtolower', ['BOO']) . PHP_EOL; // outputs 'boo'\n\necho CallableExecutionTimer::callFunc('strtoupper', 'strtoupper', ['boo']) . PHP_EOL; // outputs 'BOO'\n```\n\n\u003e NOTE: The first argument passed to **CallableExecutionTimer::callFunc(...)** is a name (conforming to PHP's method naming convention) you want to name the callable you are about to execute. This name will be used to label the information related to the execution of the callable as will be shown later on in this documentation.\n\n\u003e NOTE: The second argument passed to **CallableExecutionTimer::callFunc(...)** is the callable you are trying to execute.\n\n\u003e NOTE: The third argument passed to **CallableExecutionTimer::callFunc(...)** is an array containing all the arguments to be passed to the callable you are trying to execute. You can omit this argument if the callable to be executed does not accept any arguments.\n\n\n### Executing user defined functions\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\nfunction foobar($arg, $arg2) {\n    return __FUNCTION__ . \" got $arg and $arg2\";\n}\n\n// a function that has a by-ref argument\nfunction mega(\u0026$a){\n    $a = 55;\n    return \"function mega \\$a=$a\";\n}\n\necho CallableExecutionTimer::callFunc('foobar', 'foobar', [\"one\", \"two\"]) . PHP_EOL ; // outputs 'foobar got one and two'\n\n$bar = 77;\necho CallableExecutionTimer::callFunc('mega', 'mega', [\u0026$bar]) . PHP_EOL ; // outputs 'function mega $a=55'\n\n// $bar now has a value of 55 after the execution of the function above\n```\n\n### Executing class methods\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\nclass foo {\n\n    function bar($arg, $arg2) {\n        return __METHOD__ . \" got $arg and $arg2\";\n    }\n}\n\nclass myclass {\n\n    static function say_hello() {\n        return \"Hello!\";\n    }\n}\n\n// execute an instance method\necho CallableExecutionTimer::callFunc(\n    'fooBar', [new foo(), \"bar\"], [\"three\", \"four\"]\n) . PHP_EOL ; // outputs 'foo::bar got three and four'\n\n\n// execute a static method\n$classname = \"myclass\";\necho CallableExecutionTimer::callFunc(\n    'myclassSay_hello', [$classname, \"say_hello\"]\n) . PHP_EOL; // outputs 'Hello!'\n\n// OR\n\necho CallableExecutionTimer::callFunc(\n    'myclassSay_hello', $classname .\"::say_hello\"\n) . PHP_EOL; // also outputs 'Hello!'\n\n```\n\n### Executing parent and child class methods\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\nclass A {\n\n    public static function who() {\n        return \"A\";\n    }\n}\n\nclass B extends A {\n\n    public static function who() {\n        return \"B\";\n    }\n}\n\n// Child calling parent's implementation of method defined in both parent \u0026 child\necho CallableExecutionTimer::callFunc('B_A_who', [B::class, 'parent::who']) . PHP_EOL; // outputs 'A'\n\n// Parent calling its own method\necho CallableExecutionTimer::callFunc('A_who', [A::class, 'who']) . PHP_EOL;  // outputs 'A'\n\n// Child calling its own method\necho CallableExecutionTimer::callFunc('B_who', [B::class, 'who']) . PHP_EOL; // outputs 'B'\n```\n\n### Executing namespaced static class methods\n\n```php\n\u003c?php\nnamespace Foobar {\n\n    class Foo {\n\n        static public function test($name) {\n            return \"Hello {$name}!\";\n        }\n    }\n}\n\nnamespace {\n    //include_once './vendor/autoload.php'; //include your composer autoloader\n    use \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n    // Syntax 1\n    echo CallableExecutionTimer::callFunc(\n        'FoobarFooTest', \"\\\\Foobar\\\\Foo::test\", [\"Hannes\"]\n    ) . PHP_EOL; // outputs 'Hello Hannes!'\n\n    // Syntax 2\n    echo CallableExecutionTimer::callFunc(\n        'FoobarFooTest', [\"\\\\Foobar\\\\Foo\", 'test'], [\"Philip\"]\n    ) . PHP_EOL; // outputs 'Hello Philip!'\n}\n```\n\n### Executing lambda / anonymous functions\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n$func = function($arg1, $arg2) {\n    return $arg1 * $arg2;\n};\n\necho CallableExecutionTimer::callFunc('func', $func, [2, 4]) . PHP_EOL; // outputs 8\n\necho CallableExecutionTimer::callFunc(\n    'funcInline', \n    function($arg) { return $arg; }, \n    ['in inline lambda function!']\n) . PHP_EOL; // outputs 'in inline lambda function!'\n\n// anonymous function that accepts a by-ref argument\n$num = 5;\necho CallableExecutionTimer::callFunc(\n    'funcInlineByRef', \n    function(int \u0026$arg) { return \"\\$arg = \" . ++$arg; }, \n    [\u0026$num]\n) . PHP_EOL; // outputs '$arg = 6' \n\n// $num now has a value of 6 at this point\n```\n\n### Executing an object that is an instance of a class that has an __invoke method\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\nclass C {\n\n    public function __invoke($name) {\n        return \"Hello {$name}\";\n    }\n}\n\necho CallableExecutionTimer::callFunc('C__invoke', new C(), ['Jane!']) . PHP_EOL; // outputs 'Hello Jane!'\n```\n\nYou can also use instances of **\\FunctionExecutionTimer\\CallableExecutionTimer** to execute callables like below:\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n$callableObj1 = new CallableExecutionTimer('strtolowerCallback', 'strtolower');\n\necho $callableObj1-\u003estrtolowerCallback('BOO') . PHP_EOL; // triggers __call \u0026 outputs 'boo'\n                                                         // same as $callableObj1-\u003e__call('strtolowerCallback', ['BOO'])\n\necho $callableObj1(['BOO']) . PHP_EOL;  // triggers __invoke \u0026 outputs 'boo'\n                                        // same as $callableObj1-\u003e__invoke(['BOO'])\n\n```\n\n\u003e **WARNING:** Executing a callable that has one or more parameters that should be passed by reference should be done using **\\FunctionExecutionTimer\\CallableExecutionTimer::callFunc(...)** or executing the function by using the **__invoke(array $args)** mechanism on the instance of **\\FunctionExecutionTimer\\CallableExecutionTimer** the callable is bound to.\n\n\u003e It won't work by trying to invoke the callable on an instance of  **\\FunctionExecutionTimer\\CallableExecutionTimer**\nusing the method call syntax that triggers **__call()** under the hood.\n\nFor example, you can execute the lambda function below that accepts an argument by reference via the following two ways:\n\n```php\n\u003c?php\nuse \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n$func = function(int \u0026$arg) { \n    return \"\\$arg = \" . ++$arg; \n};\n\n// Option 1 use CallableExecutionTimer::callFunc(...)\n$num = -1;\necho CallableExecutionTimer::callFunc(\n    'funcWithRefArg', $func, [\u0026$num]\n) . PHP_EOL; // outputs '$arg = 0' \u0026 $num will have a value of 0 after this call\n\n// Option 2 using the __invoke(array $args) mechanism on the instance of \n// CallableExecutionTimer the callable is bound to\n$num = -1;\n$callableObj2 = new CallableExecutionTimer('funcWithRefArg', $func);\necho $callableObj2([\u0026$num]) . PHP_EOL;  // triggers the __invoke(array $args) mechanism\n                                        // which executes the lambda function and \n                                        // outputs '$arg = 0'.\n                                        // $num will have a value of 0 after this call\n\n\n///////////////////////////////////////////////////////////////////////////\n// NOTE: trying to invoke the function on an instance of \n// **\\FunctionExecutionTimer\\CallableExecutionTimer** using the method call\n// syntax that triggers **__call()** under the hood will not work, $num\n// will not be passed by reference as expected and you will get a PHP\n// warning to that effect.\n// DON'T DO THIS\n///////////////////////////////////////////////////////////////////////////\n$num = -1;\n$callableObj2 = new CallableExecutionTimer('funcWithRefArg', $func);\n$numRef = \u0026$num;\necho $callableObj2-\u003efuncWithRefArg($numRef) . PHP_EOL;  // Will throw a PHP Warning.\n                                                        // $numRef will not be passed by\n                                                        // ref because of the way \n                                                        // __call(string $methodName, array $args) \n                                                        // works, meaning that $num will still \n                                                        // have a value of -1 after the call.\n\n```\n\n## Retrieving execution statistics\n\nThere are two ways to retrieve information associated with each execution of callables performed via this library:\n\n1. You can call the **getLatestBenchmark()** method on an instance of **\\FunctionExecutionTimer\\CallableExecutionTimer** which you just used to execute a callable to get information about the most recent callable execution via that object. This method returns an array with the following keys (in bold, not including the colon):\n    * **function** : A string. The name (conforming to PHP's method naming convention) you labeled the callable you executed\n    * **args** : An array. Contains the arguments you passed to the callable you executed, if any, otherwise it would be an empty array.\n    * **start_time** : A float or an Integer. The timestamp in nanoseconds when the execution of the callable started.\n    * **end_time** : A float or an Integer. The timestamp in nanoseconds when the execution of the callable ended.\n    * **total_execution_time_in_seconds** : A float or an Integer. The total number of seconds it took to execute the callable.\n    * **return_value** : The value returned from the callable that was executed, if any, else NULL.\n    * **file_called_from** : A string. The absolute path to the file from which the callable was executed.\n    * **line_called_from** : An Integer. The exact line number in the file from which the callable was executed. \n\n    Below is an example:\n\n    ```php\n    \u003c?php\n    use \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n    $funcObj = new CallableExecutionTimer('strtolower', 'strtolower');\n\n    echo $funcObj-\u003estrtolower('BOO') . PHP_EOL;\n    var_export($funcObj-\u003egetLatestBenchmark());\n    ```\n\n    The code above will generate output like the one below:\n\n    ```\n    array (\n    'function' =\u003e 'strtolower',\n    'args' =\u003e\n    array (\n        0 =\u003e 'BOO',\n    ),\n    'start_time' =\u003e 81023870126000,\n    'end_time' =\u003e 81023870134000,\n    'total_execution_time_in_seconds' =\u003e 8.0E-6,\n    'return_value' =\u003e 'boo',\n    'file_called_from' =\u003e 'C:\\\\Code\\\\callable-execution-timer\\\\tester.php',\n    'line_called_from' =\u003e 105,\n    )\n    ```\n\n2. You can call **\\FunctionExecutionTimer\\CallableExecutionTimer::getBenchmarks()** to get information about the all callable executions performed via\n    * all calls to **\\FunctionExecutionTimer\\CallableExecutionTimer::callFunc(...)** \n    * and all callable executions via various instances of **\\FunctionExecutionTimer\\CallableExecutionTimer**\n\n    This method returns an array of arrays. Each sub-array has the structure of the array returned by the **getLatestBenchmark()** method described above. Below is some sample code:\n\n    ```php\n    \u003c?php\n    use \\FunctionExecutionTimer\\CallableExecutionTimer;\n\n    // First clear previous benchmark info if any\n    CallableExecutionTimer::clearBenchmarks(); \n\n    $funcObj = new CallableExecutionTimer('strtolowerMethod', 'strtolower');\n    \n    echo $funcObj-\u003estrtolowerMethod('BOO') . PHP_EOL;\n    echo $funcObj-\u003estrtolowerMethod('ABA') . PHP_EOL;\n\n    echo CallableExecutionTimer::callFunc(\n        'funcInline', \n        function($arg) { return \"Hello $arg !\"; }, \n        ['Jane']\n    ) . PHP_EOL;\n\n    var_export(CallableExecutionTimer::getBenchmarks());\n    ```\n\n    The code above will generate output like the one below:\n\n    ```\n    array (\n    0 =\u003e\n    array (\n        'function' =\u003e 'strtolowerMethod',\n        'args' =\u003e\n        array (\n        0 =\u003e 'BOO',\n        ),\n        'start_time' =\u003e 87248086831300,\n        'end_time' =\u003e 87248086840600,\n        'total_execution_time_in_seconds' =\u003e 9.3E-6,\n        'return_value' =\u003e 'boo',\n        'file_called_from' =\u003e 'C:\\\\Code\\\\callable-execution-timer\\\\tester.php',\n        'line_called_from' =\u003e 106,\n    ),\n    1 =\u003e\n    array (\n        'function' =\u003e 'strtolowerMethod',\n        'args' =\u003e\n        array (\n        0 =\u003e 'ABA',\n        ),\n        'start_time' =\u003e 87248086997700,\n        'end_time' =\u003e 87248087001600,\n        'total_execution_time_in_seconds' =\u003e 3.9E-6,\n        'return_value' =\u003e 'aba',\n        'file_called_from' =\u003e 'C:\\\\Code\\\\callable-execution-timer\\\\tester.php',\n        'line_called_from' =\u003e 108,\n    ),\n    2 =\u003e\n    array (\n        'function' =\u003e 'funcInline',\n        'args' =\u003e\n        array (\n        0 =\u003e 'Jane',\n        ),\n        'start_time' =\u003e 87248087019400,\n        'end_time' =\u003e 87248087024100,\n        'total_execution_time_in_seconds' =\u003e 4.7E-6,\n        'return_value' =\u003e 'Hello Jane !',\n        'file_called_from' =\u003e 'C:\\\\Code\\\\callable-execution-timer\\\\tester.php',\n        'line_called_from' =\u003e 110,\n    ),\n    )\n    ```\n\nIT IS RECOMMENDED THAT YOU CALL **\\FunctionExecutionTimer\\CallableExecutionTimer::clearBenchmarks()** BEFORE YOU START EXECUTING THE CALLABLES THAT YOU WANT TO GET EXECUTION INFORMATION FOR. THIS WILL CLEAR ALL PREVIOUS EXECUTION INFO FROM PRIOR CALLABLE EXECUTIONS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frotexsoft%2Fcallable-execution-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frotexsoft%2Fcallable-execution-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frotexsoft%2Fcallable-execution-timer/lists"}