10
10
# Company : Code24 BV, The Netherlands #
11
11
# Company : Rusoft Ltd, Russia #
12
12
# Date : July 1, 2015 #
13
- # version : 1.01 #
13
+ # version : 1.0.2 #
14
14
# License : Creative Commons CC-BY license #
15
15
# Website : http://www.php-benchmark-script.com #
16
16
# #
17
17
##########################################################################
18
18
*/
19
19
20
+ $ scriptVersion = '1.0.2 ' ;
21
+
22
+ $ stringTest = " the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum valar morgulis \n\rабыр \nвалар дохаÑÑ€Ð¸Ñ " ;
23
+
24
+ // Need alot of memory - more 1Gb
25
+ $ doTestArrays = false ;
26
+
20
27
function get_microtime ()
21
28
{
22
29
$ time = microtime (true );
@@ -33,7 +40,6 @@ function convert($size)
33
40
return @round ($ size /pow (1024 ,($ i =floor (log ($ size ,1024 )))),2 ).' ' .$ unit [$ i ];
34
41
}
35
42
36
-
37
43
function test_Math ($ count = 1400000 ) {
38
44
$ time_start = get_microtime ();
39
45
$ mathFunctions = array ("abs " , "acos " , "asin " , "atan " , "decbin " , "dechex " , "decoct " , "floor " , "exp " , "log1p " , "sin " , "tan " , "pi " , "is_finite " , "is_nan " , "sqrt " , "rad2deg " );
@@ -48,21 +54,149 @@ function test_Math($count = 1400000) {
48
54
return number_format (get_microtime () - $ time_start , 3 );
49
55
}
50
56
51
- function test_StringManipulation ($ count = 1300000 ) {
57
+ function test_String_Simple ($ count = 1300000 ) {
58
+ global $ stringTest ;
59
+ $ time_start = get_microtime ();
60
+ $ stringFunctions = array ("strtoupper " , "strtolower " , "strrev " , "strlen " , "str_rot13 " , "ord " , "trim " );
61
+ foreach ($ stringFunctions as $ key => $ function ) {
62
+ if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
63
+ }
64
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
65
+ foreach ($ stringFunctions as $ function ) {
66
+ $ r = call_user_func_array ($ function , array ($ stringTest ));
67
+ }
68
+ }
69
+ return number_format (get_microtime () - $ time_start , 3 );
70
+ }
71
+
72
+ function test_String_Multibyte ($ count = 130000 ) {
73
+ global $ stringTest ;
52
74
$ time_start = get_microtime ();
53
- $ stringFunctions = array ("addslashes " , "chunk_split " , "metaphone " , "strip_tags " , " crc32 " , " md5 " , " sha1 " , " strtoupper " , " strtolower " , " strrev " , " strlen " , " str_rot13 " , " soundex " , " ord " , " wordwrap " );
75
+ $ stringFunctions = array ("mb_strtoupper " , "mb_strtolower " , "mb_strlen " , "mb_strwidth " );
54
76
foreach ($ stringFunctions as $ key => $ function ) {
55
77
if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
56
78
}
57
- $ string = "the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum volar morgulis " ;
58
79
for ($ i =0 ; $ i < $ count ; $ i ++) {
59
80
foreach ($ stringFunctions as $ function ) {
60
- $ r = call_user_func_array ($ function , array ($ string ));
81
+ $ r = call_user_func_array ($ function , array ($ stringTest ));
82
+ }
83
+ }
84
+ return number_format (get_microtime () - $ time_start , 3 );
85
+ }
86
+
87
+ function test_String_Manipulation ($ count = 1300000 ) {
88
+ global $ stringTest ;
89
+ $ time_start = get_microtime ();
90
+ $ stringFunctions = array ("addslashes " , "chunk_split " , "metaphone " , "strip_tags " , "soundex " , "wordwrap " );
91
+ foreach ($ stringFunctions as $ key => $ function ) {
92
+ if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
93
+ }
94
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
95
+ foreach ($ stringFunctions as $ function ) {
96
+ $ r = call_user_func_array ($ function , array ($ stringTest ));
97
+ }
98
+ }
99
+ return number_format (get_microtime () - $ time_start , 3 );
100
+ }
101
+
102
+ function test_Hashing ($ count = 1300000 ) {
103
+ global $ stringTest ;
104
+ $ time_start = get_microtime ();
105
+ $ stringFunctions = array ("crc32 " , "md5 " , "sha1 " ,);
106
+ foreach ($ stringFunctions as $ key => $ function ) {
107
+ if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
108
+ }
109
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
110
+ foreach ($ stringFunctions as $ function ) {
111
+ $ r = call_user_func_array ($ function , array ($ stringTest ));
112
+ }
113
+ }
114
+ return number_format (get_microtime () - $ time_start , 3 );
115
+ }
116
+
117
+ function test_Json_Encode ($ count = 1300000 ) {
118
+ global $ stringTest ;
119
+ $ time_start = get_microtime ();
120
+ $ stringFunctions = array ("json_encode " ,);
121
+ foreach ($ stringFunctions as $ key => $ function ) {
122
+ if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
123
+ }
124
+ $ data = array (
125
+ $ stringTest ,
126
+ 123456 ,
127
+ 123.456 ,
128
+ array (123456 ),
129
+ null ,
130
+ false ,
131
+ );
132
+ foreach ($ stringFunctions as $ function ) {
133
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
134
+ foreach ($ data as $ value ) {
135
+ $ r = call_user_func_array ($ function , array ($ value ));
136
+ }
137
+ }
138
+ }
139
+ return number_format (get_microtime () - $ time_start , 3 );
140
+ }
141
+
142
+ function test_Json_Decode ($ count = 1300000 ) {
143
+ global $ stringTest ;
144
+ $ time_start = get_microtime ();
145
+ $ stringFunctions = array ("json_decode " ,);
146
+ foreach ($ stringFunctions as $ key => $ function ) {
147
+ if (!function_exists ($ function )) unset($ stringFunctions [$ key ]);
148
+ }
149
+ $ data = array (
150
+ $ stringTest ,
151
+ 123456 ,
152
+ 123.456 ,
153
+ array (123456 ),
154
+ null ,
155
+ false ,
156
+ );
157
+ foreach ($ data as $ key => $ value ) {
158
+ $ data [ $ key ] = json_encode ($ value );
159
+ }
160
+ foreach ($ stringFunctions as $ function ) {
161
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
162
+ foreach ($ data as $ value ) {
163
+ $ r = call_user_func_array ($ function , array ($ value ));
164
+ }
61
165
}
62
166
}
63
167
return number_format (get_microtime () - $ time_start , 3 );
64
168
}
65
169
170
+ function test_Array_Fill ($ count = 3000 ) {
171
+ global $ doTestArrays ;
172
+ if (!$ doTestArrays ) return '-.--- ' ;
173
+
174
+ $ time_start = get_microtime ();
175
+ for ($ i = 0 ; $ i < $ count ; ++$ i ) {
176
+ for ($ j = 0 ; $ j < $ count ; ++$ j ) {
177
+ $ X [ $ i ][ $ j ] = $ i * $ j ;
178
+ }
179
+ }
180
+ return number_format (get_microtime () - $ time_start , 3 );
181
+ }
182
+
183
+ function test_Array_Unset ($ count = 3000 ) {
184
+ global $ doTestArrays ;
185
+ if (!$ doTestArrays ) return '-.--- ' ;
186
+
187
+ $ time_start = get_microtime ();
188
+ $ X = range (0 , $ count );
189
+ for ($ i = 0 ; $ i < $ count ; ++$ i ) {
190
+ $ X [ $ i ] = range (0 , $ count );
191
+ }
192
+ for ($ i = $ count -1 ; $ i >= 0 ; $ i --) {
193
+ for ($ j = 0 ; $ j < $ count ; ++$ j ) {
194
+ unset($ X [ $ i ][ $ j ]);
195
+ }
196
+ unset($ X [ $ i ]);
197
+ }
198
+ return number_format (get_microtime () - $ time_start , 3 );
199
+ }
66
200
67
201
function test_Loops ($ count = 190000000 ) {
68
202
$ time_start = get_microtime ();
@@ -71,24 +205,42 @@ function test_Loops($count = 190000000) {
71
205
return number_format (get_microtime () - $ time_start , 3 );
72
206
}
73
207
74
-
75
208
function test_IfElse ($ count = 90000000 ) {
76
209
$ time_start = get_microtime ();
77
210
for ($ i =0 ; $ i < $ count ; $ i ++) {
78
211
if ($ i == -1 ) {
79
212
} elseif ($ i == -2 ) {
80
213
} else if ($ i == -3 ) {
81
214
} else {
82
- }
215
+ }
83
216
}
84
217
return number_format (get_microtime () - $ time_start , 3 );
85
218
}
86
-
87
-
219
+
220
+ function test_Ternary ($ count = 90000000 ) {
221
+ $ time_start = get_microtime ();
222
+ for ($ i =0 ; $ i < $ count ; $ i ++) {
223
+ $ r = ($ i % 2 == 1 )
224
+ ? ( ($ i % 3 == 1 )
225
+ ? ( ($ i % 5 == 1 )
226
+ ? 3
227
+ : 2 )
228
+ : 1 )
229
+ : 0 ;
230
+ }
231
+ return number_format (get_microtime () - $ time_start , 3 );
232
+ }
233
+
88
234
$ total = 0 ;
89
235
$ functions = get_defined_functions ();
90
236
$ line = str_pad ("- " ,38 ,"- " );
91
- echo "<pre> \n$ line \n| " .str_pad ("PHP BENCHMARK SCRIPT " ,36 ," " ,STR_PAD_BOTH )."| \n$ line \nStart : " .date ("Y-m-d H:i:s " )."\nServer : " .php_uname ()."\nPHP version : " .PHP_VERSION ."\nPlatform : " .PHP_OS . "\n$ line \n" ;
237
+ echo "<pre> \n$ line \n| " .str_pad ("PHP BENCHMARK SCRIPT " ,36 ," " ,STR_PAD_BOTH )
238
+ ."| \n$ line \nStart : " .date ("Y-m-d H:i:s " )
239
+ ."\nServer : " .php_uname ()
240
+ ."\nPHP version : " .PHP_VERSION
241
+ ."\nBenchmark version : " .$ scriptVersion
242
+ ."\nPlatform : " .PHP_OS
243
+ . "\n$ line \n" ;
92
244
foreach ($ functions ['user ' ] as $ user ) {
93
245
if (preg_match ('/^test_/ ' , $ user )) {
94
246
$ result = $ user ();
0 commit comments