research.php
Gesponsorde koppelingen
PHP script bestanden
Code (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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Research Object
*
* This object contains one research and it runs some tests.
*
* @author Wouter J
* @since Version 1.0
*/
class Research
{
/**
* All tests in this research
*
* @access protected
* @var Array
*/
protected $tests = Array();
/**
* The name of the research
*
* @access protected
* @var String
*/
protected $name;
/**
* The times results
*
* @access protected
* @var Array
*/
protected $times = Array();
/**
* The percentage results
*
* @access protected
* @var Array
*/
protected $percentages = Array();
/**
* How may times the test would repeated. Default: 1000
*
* @access protected
* @var Int
*/
protected $repeat = 1000;
/**
* The constructor
*
* Set up the name of the research.
*
* @param string $name The name of the research
* @return void
*/
public function __construct( $name )
{
$this->name = (string) $name;
}
/**
* addTest
*
* With this method you can add tests to the research
*
* @param object $test The test object
* @return void
*/
public function addTest( Test $test )
{
$this->tests[$test->getName()] = $test;
}
/**
* setRepeat
*
* Set a number how much the test would repeated
*
* @param int $repeat The repeat count
* @return void
*/
public function setRepeat( $repeat )
{
$this->repeat = $repeat;
}
/**
* runTests
*
* Run all tests
*
* @return void
*/
public function runTests()
{
foreach( $this->tests as $name => $test )
{
ob_start();
Timer::start();
for( $i=0; $i < $this->repeat; $i++ )
{
Timer::setMarker('Test-'.$i.'-start');
$test->run();
Timer::setMarker('Test-'.$i.'-end');
}
Timer::end();
$this->times[$name] = Timer::getResult();
unset($time);
ob_end_clean();
}
$this->countPercentages();
}
/**
* count percentages
*
* Count all percentages
*
* @return void
*/
protected function countPercentages()
{
$key = 100 / min($this->times);
foreach( $this->times as $name => $time )
{
$this->percentages[$name] = round($key * $time);
}
}
/**
* getResults
*
* Get the results
*
* @return array $result The times and percentages
*/
public function getResults()
{
$result = Array(
'times' => Array(),
'percentages' => Array()
);
foreach( $this->times as $name => $time )
{
$result['times'][$name] = $time / $this->repeat;
$result['percentages'][$name] = $this->percentages[$name];
}
return $result;
}
/**
* getName
*
* Get the research name
* @retrurn string $name The name of the research
*/
public function getName()
{
return $this->name;
}
}
/**
* Research Object
*
* This object contains one research and it runs some tests.
*
* @author Wouter J
* @since Version 1.0
*/
class Research
{
/**
* All tests in this research
*
* @access protected
* @var Array
*/
protected $tests = Array();
/**
* The name of the research
*
* @access protected
* @var String
*/
protected $name;
/**
* The times results
*
* @access protected
* @var Array
*/
protected $times = Array();
/**
* The percentage results
*
* @access protected
* @var Array
*/
protected $percentages = Array();
/**
* How may times the test would repeated. Default: 1000
*
* @access protected
* @var Int
*/
protected $repeat = 1000;
/**
* The constructor
*
* Set up the name of the research.
*
* @param string $name The name of the research
* @return void
*/
public function __construct( $name )
{
$this->name = (string) $name;
}
/**
* addTest
*
* With this method you can add tests to the research
*
* @param object $test The test object
* @return void
*/
public function addTest( Test $test )
{
$this->tests[$test->getName()] = $test;
}
/**
* setRepeat
*
* Set a number how much the test would repeated
*
* @param int $repeat The repeat count
* @return void
*/
public function setRepeat( $repeat )
{
$this->repeat = $repeat;
}
/**
* runTests
*
* Run all tests
*
* @return void
*/
public function runTests()
{
foreach( $this->tests as $name => $test )
{
ob_start();
Timer::start();
for( $i=0; $i < $this->repeat; $i++ )
{
Timer::setMarker('Test-'.$i.'-start');
$test->run();
Timer::setMarker('Test-'.$i.'-end');
}
Timer::end();
$this->times[$name] = Timer::getResult();
unset($time);
ob_end_clean();
}
$this->countPercentages();
}
/**
* count percentages
*
* Count all percentages
*
* @return void
*/
protected function countPercentages()
{
$key = 100 / min($this->times);
foreach( $this->times as $name => $time )
{
$this->percentages[$name] = round($key * $time);
}
}
/**
* getResults
*
* Get the results
*
* @return array $result The times and percentages
*/
public function getResults()
{
$result = Array(
'times' => Array(),
'percentages' => Array()
);
foreach( $this->times as $name => $time )
{
$result['times'][$name] = $time / $this->repeat;
$result['percentages'][$name] = $this->percentages[$name];
}
return $result;
}
/**
* getName
*
* Get the research name
* @retrurn string $name The name of the research
*/
public function getName()
{
return $this->name;
}
}