Skip to content

Commit

Permalink
Timer: upgrade method, use english term
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Sep 13, 2020
1 parent 3388234 commit 89b6159
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 103 deletions.
25 changes: 20 additions & 5 deletions example/timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@

$time = new Timer;

$time->chapitre_debut('readfile Readme');
// Get the time executed in delimited code
$time->chapterStart('readfile Readme');
readfile(__DIR__.'/../readme.md');
//somecode...
$time->chapitre_fin('readfile Readme');
$time->chapterEnd('readfile Readme');

$time->chapitre_debut('Sleep 2s');
$time->chapterStart('Sleep 2s');
sleep(2);
$time->chapitre_fin('Sleep 2s');
$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__]);

// 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('html');
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');
19 changes: 19 additions & 0 deletions example/timer_simple_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
use Jgauthi\Component\Debug\Timer;

// In this example, the vendor folder is located in "example/"
require_once __DIR__.'/vendor/autoload.php';

// Use timer without set manually outPut method
$timer = Timer::init(false, Timer::EXPORT_FORMAT_COMMENT);
// OR
// $timer = Timer::init();
// OR
// Timer::init(); // if you don't need the var '$timer'


// somecode
// ...
$timer->step('Some code');

// The timer will be displayed at footer
Loading

0 comments on commit 89b6159

Please sign in to comment.