Skip to content

Commit 1273bb2

Browse files
committed
feat(Timer) : ajout de la méthode record pour mesurer le temps d'exécution d'une fonction callable
1 parent 8fdcdca commit 1273bb2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Debug/Timer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ public function has(string $name): bool
105105
return array_key_exists(strtolower($name), $this->timers);
106106
}
107107

108+
/**
109+
* Exécute la fonction callable et mesure son temps d'exécution.
110+
* Renvoie sa valeur de retour, le cas échéant.
111+
*
112+
* @param string $name Le nom du minuteur.
113+
* @param callable(): mixed $callable Fonction callable à exécuter.
114+
*/
115+
public function record(string $name, callable $callable):mixed
116+
{
117+
$this->start($name);
118+
$returnValue = $callable();
119+
$this->stop($name);
120+
121+
return $returnValue;
122+
}
123+
108124
/**
109125
* Renvoie la durée d'une minuterie enregistrée.
110126
*

0 commit comments

Comments
 (0)