-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.php
More file actions
42 lines (30 loc) · 1.09 KB
/
timer.php
File metadata and controls
42 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
use Jgauthi\Component\Debug\Timer;
// In this example, the vendor folder is located in "example/"
require_once __DIR__.'/vendor/autoload.php';
$time = new Timer;
// Get the time executed in delimited code
$time->chapterStart('readfile Readme');
readfile(__DIR__.'/../readme.md');
//somecode...
$time->chapterEnd('readfile Readme');
$time->chapterStart('Sleep 2s');
sleep(2);
$time->chapterEnd('Sleep 2s');
// Calculate the execution average of a function in a loop with chapters
// In this example: 10 Loops, 100 executions by loop (total: 1000 executions)
$time->testLoop('filemtime', 10, 100, [__FILE__]);
// [Alternative] method stand-alone
$file = __FILE__;
var_dump(
'filemtime average time: '.
Timer::loopFunction(function() use ($file): void { filemtime($file); } )
);
// Define a location in the code to get the current time spent
$time->step('After testLoop');
sleep(1);
$time->step('After sleep 1s');
$time->stop();
echo $time->outPut(Timer::EXPORT_FORMAT_HTML);
// You can export Chapter logs to CSV file
$time->exportChapter(sys_get_temp_dir().'/timer_chapter_export.csv');