Skip to content

Instantly share code, notes, and snippets.

@DesolatorMagno
Created July 15, 2021 13:42
Show Gist options
  • Save DesolatorMagno/455a703e0a8b071fd5fa3af6a11b8e68 to your computer and use it in GitHub Desktop.
Save DesolatorMagno/455a703e0a8b071fd5fa3af6a11b8e68 to your computer and use it in GitHub Desktop.
tomar el tiempo de ejecucion de partes del codigo.
<?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);
}
}
<?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