Created
July 15, 2021 13:42
-
-
Save DesolatorMagno/455a703e0a8b071fd5fa3af6a11b8e68 to your computer and use it in GitHub Desktop.
tomar el tiempo de ejecucion de partes del codigo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Chronometer | |
{ | |
private $start = []; | |
private $end = []; | |
public function start(string $name = 'default'): void | |
{ | |
$this->start[$name] = microtime(true); | |
} | |
public function end(string $name = 'default'): void | |
{ | |
$this->end[$name] = microtime(true); | |
} | |
public function totalExecution(string $name = 'default'): float | |
{ | |
return ($this->end[$name] - $this->start[$name]); | |
} | |
public function totalExecutionMin(string $name = 'default'): float | |
{ | |
return ($this->totalExecution($name) / 60); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public example function(){ | |
$chronometer = New Chronometer(); | |
$chronometer->start('app'); | |
//do app things | |
$chronometer->start('usersUpdate'); | |
foreach ($users as $key => $value) { | |
# do things to each user | |
} | |
$chronometer->end('usersUpdate'); | |
# Do more things | |
$chronometer->end('app'); | |
var_dump('The user update toke ' . $chronometer->totalExecution('usersUpdate')) | |
var_dump('The app toke ' . $chronometer->totalExecution('app')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment