You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+127-2Lines changed: 127 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ A simple PHP library for tracking the total amount of time a
10
10
function / method) takes to execute (it can also return the result of executing
11
11
the callable, if desired).
12
12
13
+
If 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.
14
+
13
15
14
16
## Installation
15
17
@@ -32,7 +34,7 @@ This library also provides information associated with each execution / invocati
32
34
* the absolute path to the file in which the callable was called (string)
33
35
* the exact line number in the file in which the callable was called (integer)
34
36
35
-
## Basic usage: Executing callables
37
+
## Executing callables
36
38
37
39
### Executing built-in php functions
38
40
@@ -287,4 +289,127 @@ $callableObj2->funcWithRefArg($numRef); // Will throw a PHP Warning.
287
289
// works, meaning that $num will still
288
290
// have a value of -1 after the call.
289
291
290
-
```
292
+
```
293
+
294
+
295
+
## Retrieving execution statistics
296
+
297
+
There are two ways to retrieve information associated with each execution of callables performed via this library:
298
+
299
+
1. 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):
300
+
***function** : A string. The name (conforming to PHP's method naming convention) you labeled the callable you executed
301
+
***args** : An array. Contains the arguments you passed to the callable you executed, if any, otherwise it would be an empty array.
302
+
***start_time** : A float or an Integer. The timestamp in nanoseconds when the execution of the callable started.
303
+
***end_time** : A float or an Integer. The timestamp in nanoseconds when the execution of the callable ended.
304
+
***total_execution_time_in_seconds** : A float or an Integer. The total number of seconds it took to execute the callable.
305
+
***return_value** : The value returned from the callable that was executed, if any, else NULL.
306
+
***file_called_from** : A string. The absolute path to the file from which the callable was executed.
307
+
***line_called_from** : An Integer. The exact line number in the file from which the callable was executed.
308
+
309
+
Below is an example:
310
+
311
+
```php
312
+
<?php
313
+
use \FunctionExecutionTimer\CallableExecutionTimer;
314
+
315
+
$funcObj = new CallableExecutionTimer('strtolower', 'strtolower');
316
+
317
+
$funcObj->strtolower('BOO');
318
+
var_export($funcObj->getLatestBenchmark());
319
+
```
320
+
321
+
The code above will generate output like the one below:
2. You can call **\FunctionExecutionTimer\CallableExecutionTimer::getBenchmarks()** to get information about the all callable executions performed via
340
+
* all calls to **\FunctionExecutionTimer\CallableExecutionTimer::callFunc(...)**
341
+
* and all callable executions via various instances of **\FunctionExecutionTimer\CallableExecutionTimer**
342
+
343
+
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:
344
+
345
+
```php
346
+
<?php
347
+
use \FunctionExecutionTimer\CallableExecutionTimer;
348
+
349
+
// First clear previous benchmark info if any
350
+
CallableExecutionTimer::clearBenchmarks();
351
+
352
+
$funcObj = new CallableExecutionTimer('strtolowerMethod', 'strtolower');
IT 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.
0 commit comments