Skip to content

Instantly share code, notes, and snippets.

@isholgueras
Last active March 8, 2019 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isholgueras/f062658ed821b494dda5f99a41c9a195 to your computer and use it in GitHub Desktop.
Save isholgueras/f062658ed821b494dda5f99a41c9a195 to your computer and use it in GitHub Desktop.
<?php
// APPEND into the class you wanna test.
/** @var array */
private $time;
private function initTimeMeasurement() {
$now = new \DateTimeImmutable('now');
$this->time = [];
$this->time[] = [
'time' => $now,
'text' => $now->format('H:i:v'),
'from_previous' => 0,
'from_initial' => 0,
'message' => 'Init. Started at ' . $now->format('H:i:v'),
];
}
private function measureTime($message = '') {
$now = new \DateTimeImmutable('now');
$initial = $this->time[0]['time']->diff($now);
$previous = $this->time[count($this->time) - 1]['time']->diff($now);
$seconds_from_initial = (60 * $initial->m) + $initial->s + $initial->f;
$seconds_from_previous = (60 * $previous->m) + $previous->s + $previous->f;
$this->time[] = [
'time' => $now,
'text' => $now->format('H:i:v'),
'from_initial' => $seconds_from_initial,
'from_previous' => $seconds_from_previous,
'message' => $message . ". Seconds from INITIAL: $seconds_from_initial and Seconds from PREVIOUS: $seconds_from_previous",
];
}
private function getTimeReport() {
return array_map(
function ($time) {
return $time['message'];
},
$this->time
);
}
/*
Array
(
[0] => Init. Started at 13:12:425
[1] => Entities loaded. Seconds from INIT: 0.003158 and Seconds from PREVIOUS: 0.003158
[2] => Entity 526 rendered. Seconds from INIT: 0.869489 and Seconds from PREVIOUS: 0.866331
[3] => Entity 715 rendered. Seconds from INIT: 1.232432 and Seconds from PREVIOUS: 0.362943
[4] => Entity 758 rendered. Seconds from INIT: 1.408245 and Seconds from PREVIOUS: 0.175813
[5] => Entity 878 rendered. Seconds from INIT: 1.620759 and Seconds from PREVIOUS: 0.212514
[6] => Entity 873 rendered. Seconds from INIT: 1.911883 and Seconds from PREVIOUS: 0.291124
[7] => Entity 913 rendered. Seconds from INIT: 2.121788 and Seconds from PREVIOUS: 0.209905
[8] => Entity 881 rendered. Seconds from INIT: 2.347735 and Seconds from PREVIOUS: 0.225947
[9] => Entity 884 rendered. Seconds from INIT: 2.548095 and Seconds from PREVIOUS: 0.20036
[10] => Entity 883 rendered. Seconds from INIT: 2.790679 and Seconds from PREVIOUS: 0.242584
[11] => Entity 863 rendered. Seconds from INIT: 2.986637 and Seconds from PREVIOUS: 0.195958
[12] => Entity 906 rendered. Seconds from INIT: 3.178667 and Seconds from PREVIOUS: 0.19203
[13] => Entity 868 rendered. Seconds from INIT: 3.546457 and Seconds from PREVIOUS: 0.36779
[14] => Entity 871 rendered. Seconds from INIT: 3.923366 and Seconds from PREVIOUS: 0.376909
[15] => Entity 851 rendered. Seconds from INIT: 4.196411 and Seconds from PREVIOUS: 0.273045
[16] => Entity 923 rendered. Seconds from INIT: 4.447689 and Seconds from PREVIOUS: 0.251278
[17] => Process finished. Seconds from INIT: 4.447721 and Seconds from PREVIOUS: 3.2000000000032E-5
)
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment