-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeExecution.php
58 lines (53 loc) · 1.6 KB
/
timeExecution.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class timeExecution
{
/**
* @return float
*/
public static function start()
{
self::printColor(str_repeat("=", 100) . PHP_EOL);
$timeStart = microtime(true);
self::printColor("Memory: " . memory_get_peak_usage(true) . " (" . ((memory_get_peak_usage(true) / 1024) / 1024) . " MB)" . PHP_EOL);
self::printColor(str_repeat("=", 100) . PHP_EOL);
return $timeStart;
}
/**
* @param $timeStart
* @return float
*/
public static function end($timeStart)
{
$timeEnd = microtime(true);
$executionTime = ($timeEnd - $timeStart);
self::printColor("Memory: " . memory_get_peak_usage(true) . " (" . ((memory_get_peak_usage(true) / 1024) / 1024) . " MB)" . PHP_EOL);
self::printColor(str_repeat("=", 100) . PHP_EOL);
self::printColor("Total Execution Time: " . $executionTime . PHP_EOL, 'info');
self::printColor(str_repeat("=", 100) . PHP_EOL);
return $executionTime;
}
/**
* @param $str
* @param $type
* @return void
*/
public static function printColor($str, $type = 'success')
{
switch ($type) {
case 'error':
echo "\033[31m$str \033[0m\n";
break;
case 'success':
echo "\033[32m$str \033[0m\n";
break;
case 'warning':
echo "\033[33m$str \033[0m\n";
break;
case 'info':
echo "\033[36m$str \033[0m\n";
break;
default:
break;
}
}
}