-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeyTest.php
More file actions
119 lines (104 loc) · 2.99 KB
/
TimeyTest.php
File metadata and controls
119 lines (104 loc) · 2.99 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<?php
include 'YeOldTimey.php';
//starts timer
$newTimer = new YeOldenTimey;
//pause
sleep(3);
//add lap
$newTimer->laps('set', 1);
//pause
sleep(1);
//add lap
$newTimer->laps('set', 2);
//pause again
sleep(2);
//stop timer
$totaltime = $newTimer->timer('get');
//BUILD HTML
$i = 1;
$laps = array();
//set up output vars
$startHTML = 'Start time: ' . $newTimer->starttime;
$endHTML = 'End Time: ' . $newTimer->endtime;
$totalHTML = 'Total time elapsed: ' . $totaltime;
$lapsHTML = '';
$lapsStart = '<li>';
$lapsEnd = '</li>';
//get laps
$laps = $newTimer->laps('get');
foreach( $laps as $l )
{
$lapsHTML = $lapsHTML . $lapsStart . 'Lap #' . $i . ' time: ' . $l . ' and total difference from end time:' . $newTimer->laps('compare', $i) . $lapsEnd;
$i++;
}
?>
<html>
<head>
<title>Ye Olde Timey Test</title>
<meta charset="UTF-8">
<style>
/* clear */
body {margin: 0; padding:0; outline:none; border:none;}
body {width: 60%; margin: 0 auto 0 auto;}
</style>
</head>
<body>
<h1>Ye Olde Timey - A Test</h1>
<p>Just a stupid simple tool to help time scripts.</p>
<h2>Instructions:</h2>
<div>
<p>The test consists of two parts, really. The main timer and lap times.</p>
<h4>Timer:</h4>
<ul>
<li>
<p>Initializing:
<pre>$newTimer = new YeOldenTimey;</pre>
This also starts the timer. You can RESTART the timer after initializing by:
<pre>$newTimer->timer('restart');</pre>
</p>
</li>
<li>
<p>Stop the timer:
<pre>$newTimer->timer('get');</pre>
This stops the timer and returns the end time.<br />
Restarting the timer will not clear the end time by default. You can force it, though:
<pre>$newTimer->timer('restart', true );</pre>
</p>
</li>
</ul>
<h4>Lap Times:</h4>
<ul>
<li>
<p>Trigger a lap time:
<pre>$newTimer->laps('set', 1);</pre>
Both arguments are optional, but if you want to easily track lap times later, you should pass both.
The first argument is the action, in this case SET creates a new lap time.
The second argument is the name of the lap time. I used numbers in this example but you can use strings if you like.
</p>
</li>
<li>
<p>Get a lap time:
<pre>$newTimer->timer('get', 1);</pre>
This returns the lap time saved with the name of 1. Remember that whatever you passed as the name is how you get it back. <br />
If you did not pass a name when you set the lap time, you will have to manually go through the array which is retrieved like so:
<pre>$newTimer->timer('get');</pre>
</p>
</li>
<li>
<p>Compare a lap time:
<pre>$newTimer->laps('compare', 1)</pre>
This compares the lap time to the end time and returns the result. If end time hasn't been set yet, it uses the current time.
</p>
</li>
</ul>
</div>
<h2>Test Output:</h2>
<ul>
<li><?php echo $startHTML; ?></li>
<?php echo $lapsHTML ?>
<li><?php echo $endHTML; ?></li>
<li><?php echo $totalHTML; ?></li>
</ul>
</body>
</html>