Hi!
Deze vond ik net nog op mijn host, en ik doe er zelf niks mee. Misschien heeft iemand er iets aan.
De class is niet compleet, en werkt niet optimaal, zelf knutselen zal dus waarschijnlijk wel gewenst zijn.
Ik geef om die reden ook eigenlijk geen support voor de code. Vragen mag altijd uiteraard.
De class 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @author Rik Somers
* @copyright 2012
*/
class Timer {
private static $arrLogStart = array();
private static $arrUpdates = array();
private static $arrLogStop = array();
private static $arrLogErrors = array();
private static $intStart;
private static $intStop;
public static function startTimer() {
self::$intStart = microtime(true);
}
public static function stopTimer() {
self::$intStop = microtime(true);
}
public static function addEvent($strKey, $strEvent = NULL) {
if(!isset(self::$intStart)) {
self::logError([ . microtime(true) . ] Timer class not started. Starting now. );
self:SMILEYYYYYYYYYYYBEGIN:startTimer();
}
self::$arrLogStart[$strKey] = microtime(true);
}
public static function updateEvent() {
// TODO: Add update functionality for Timer.
}
public static function stopEvent($strKey, $strEvent = NULL) {
if(array_key_exists($strKey, self::$arrLogStart)) {
self::$arrLogStop[$strKey] = microtime(true);
}
else {
self::logError(Event { . $strKey . } never started.);
}
}
private static function logError($strErrMessage) {
self::$arrLogErrors[$strErrMessage] = microtime(true);
}
public static function showTimer($strEvent = NULL) {
$strReturn = ;
if($strEvent === NULL)
{
foreach(self::$arrLogStart as $strKey => $intTime) {
if(array_key_exists($strKey, self::$arrLogStop)) {
$strReturn .= [ . $strKey . ] . (self::$arrLogStop[$strKey] - $intTime) . s [ . (self::$arrLogStop[$strKey] - self::$intStart) . s since start]
;
}
}
}
else
{
if(array_key_exists($strEvent, self::$arrLogStart)) {
if(array_key_exists($strEvent, self::$arrLogStop)) {
$strReturn .= [ . $strEvent . ] . (self::$arrLogStop[$strEvent] - $intTime) . s [ . (self::$arrLogStop[$strEvent] - self::$intStart) . s since start]
;
}
}
}
return $strReturn;
}
public static function showTimerErrors() {
if(count(self::$arrLogErrors) != 0) {
$strReturn = ;
foreach(self::$arrLogErrors as $strKey => $intTime) {
$strReturn .= $strKey . [ . (self::$arrLogErrors[$strKey] - self::$intStart) . s since start]
;
}
return $strReturn;
}
else {
return No errors occured.;
}
}
}
?>
Voorbeeld 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
/**
* @author Rik Somers
* @copyright 2012
*/
include(app/inc/bootstrap.php); // bootstrap heeft een autoloader. Gebruik je eigen autoloader of laadt de class handmatig in!
Timer:SMILEYYYYYYYYYYYBEGIN:startTimer();
Timer::addEvent(Executing useless for);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for);
Timer::addEvent(Executing useless for 2);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for 2);
Timer::addEvent(Executing useless for 3);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for 3);
echo Timer:SMILEYYYYYYYYYYYBEGIN:showTimer();
?>
- Rik
Deze vond ik net nog op mijn host, en ik doe er zelf niks mee. Misschien heeft iemand er iets aan.
De class is niet compleet, en werkt niet optimaal, zelf knutselen zal dus waarschijnlijk wel gewenst zijn.
Ik geef om die reden ook eigenlijk geen support voor de code. Vragen mag altijd uiteraard.
De class
Spoiler tonen
Codeblok (timer.cls.php):
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @author Rik Somers
* @copyright 2012
*/
class Timer {
private static $arrLogStart = array();
private static $arrUpdates = array();
private static $arrLogStop = array();
private static $arrLogErrors = array();
private static $intStart;
private static $intStop;
public static function startTimer() {
self::$intStart = microtime(true);
}
public static function stopTimer() {
self::$intStop = microtime(true);
}
public static function addEvent($strKey, $strEvent = NULL) {
if(!isset(self::$intStart)) {
self::logError([ . microtime(true) . ] Timer class not started. Starting now. );
self:SMILEYYYYYYYYYYYBEGIN:startTimer();
}
self::$arrLogStart[$strKey] = microtime(true);
}
public static function updateEvent() {
// TODO: Add update functionality for Timer.
}
public static function stopEvent($strKey, $strEvent = NULL) {
if(array_key_exists($strKey, self::$arrLogStart)) {
self::$arrLogStop[$strKey] = microtime(true);
}
else {
self::logError(Event { . $strKey . } never started.);
}
}
private static function logError($strErrMessage) {
self::$arrLogErrors[$strErrMessage] = microtime(true);
}
public static function showTimer($strEvent = NULL) {
$strReturn = ;
if($strEvent === NULL)
{
foreach(self::$arrLogStart as $strKey => $intTime) {
if(array_key_exists($strKey, self::$arrLogStop)) {
$strReturn .= [ . $strKey . ] . (self::$arrLogStop[$strKey] - $intTime) . s [ . (self::$arrLogStop[$strKey] - self::$intStart) . s since start]
;
}
}
}
else
{
if(array_key_exists($strEvent, self::$arrLogStart)) {
if(array_key_exists($strEvent, self::$arrLogStop)) {
$strReturn .= [ . $strEvent . ] . (self::$arrLogStop[$strEvent] - $intTime) . s [ . (self::$arrLogStop[$strEvent] - self::$intStart) . s since start]
;
}
}
}
return $strReturn;
}
public static function showTimerErrors() {
if(count(self::$arrLogErrors) != 0) {
$strReturn = ;
foreach(self::$arrLogErrors as $strKey => $intTime) {
$strReturn .= $strKey . [ . (self::$arrLogErrors[$strKey] - self::$intStart) . s since start]
;
}
return $strReturn;
}
else {
return No errors occured.;
}
}
}
?>
Voorbeeld
Spoiler tonen
Codeblok (voorbeeld.php):
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
/**
* @author Rik Somers
* @copyright 2012
*/
include(app/inc/bootstrap.php); // bootstrap heeft een autoloader. Gebruik je eigen autoloader of laadt de class handmatig in!
Timer:SMILEYYYYYYYYYYYBEGIN:startTimer();
Timer::addEvent(Executing useless for);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for);
Timer::addEvent(Executing useless for 2);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for 2);
Timer::addEvent(Executing useless for 3);
for($i=0; $i < 1000000; $i++) {
// Do nothing lol
}
Timer:SMILEYYYYYYYYYYYBEGIN:stopEvent(Executing useless for 3);
echo Timer:SMILEYYYYYYYYYYYBEGIN:showTimer();
?>
- Rik