FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
php-src/Zend/micro_bench.php at master · EndlessCoding/php-src · GitHub
EndlessCoding
/
php-src
Public
forked from
php/php-src
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
php-src
/
Zend
/
micro_bench.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
358 lines (308 loc) · 6.41 KB
Breadcrumbs
php-src
/
Zend
/
micro_bench.php
Copy path
File metadata and controls
358 lines (308 loc) · 6.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
function
hallo
() {
}
function
simpleucall
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
;
$
i
++)
hallo
();
}
function
simpleudcall
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
;
$
i
++)
hallo2
();
}
function
hallo2
() {
}
function
simpleicall
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
;
$
i
++)
func_num_args
();
}
class
Foo {
static
$
a
=
0
;
public
$
b
=
0
;
const
TEST
=
0
;
static
function
read_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
self
::
$
a
;
}
}
static
function
write_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
self
::
$
a
=
0
;
}
}
static
function
isset_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
isset
(
self
::
$
a
);
}
}
static
function
empty_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
empty
(
self
::
$
a
);
}
}
static
function
f
() {
}
static
function
call_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
self
::
f
();
}
}
function
read_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
this
->
b
;
}
}
function
write_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
this
->
b
=
0
;
}
}
function
assign_add_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
this
->
b
+=
2
;
}
}
function
pre_inc_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
++
$
this
->
b
;
}
}
function
pre_dec_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
--
$
this
->
b
;
}
}
function
post_inc_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
this
->
b
++;
}
}
function
post_dec_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
this
->
b
--;
}
}
function
isset_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
isset
(
$
this
->
b
);
}
}
function
empty_prop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
empty
(
$
this
->
b
);
}
}
function
g
() {
}
function
call
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
this
->
g
();
}
}
function
read_const
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
this
::
TEST
;
}
}
}
function
read_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
= Foo::
$
a
;
}
}
function
write_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
Foo::
$
a
=
0
;
}
}
function
isset_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
isset
(Foo::
$
a
);
}
}
function
empty_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
empty
(Foo::
$
a
);
}
}
function
call_static
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
Foo::
f
();
}
}
function
create_object
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
new
Foo
();
}
}
define
(
'
TEST
'
,
null
);
function
read_const
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
TEST
;
}
}
function
read_auto_global
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
_GET
;
}
}
$
g_var
=
0
;
function
read_global_var
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
GLOBALS
[
'
g_var
'
];
}
}
function
read_hash
(
$
n
) {
$
hash
=
array
(
'
test
'
=>
0
);
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
hash
[
'
test
'
];
}
}
function
read_str_offset
(
$
n
) {
$
str
=
"
test
"
;
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
str
[
1
];
}
}
function
issetor
(
$
n
) {
$
val
=
array
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
val
?:
null
;
}
}
function
issetor2
(
$
n
) {
$
f
=
false
;
$
j
=
0
;
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
f
?:
$
j
+
1
;
}
}
function
ternary
(
$
n
) {
$
val
=
array
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
$
f
=
false
;
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
f
?
null
:
$
val
;
}
}
function
ternary2
(
$
n
) {
$
f
=
false
;
$
j
=
0
;
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
$
x
=
$
f
?
$
f
:
$
j
+
1
;
}
}
/*****/
function
empty_loop
(
$
n
) {
for
(
$
i
=
0
;
$
i
<
$
n
; ++
$
i
) {
}
}
function
getmicrotime
()
{
$
t
=
gettimeofday
();
return
(
$
t
[
'
sec
'
] +
$
t
[
'
usec
'
] /
1000000
);
}
function
start_test
()
{
ob_start
();
return
getmicrotime
();
}
function
end_test
(
$
start
,
$
name
,
$
overhead
=
null
)
{
global
$
total
;
global
$
last_time
;
$
end
=
getmicrotime
();
ob_end_clean
();
$
last_time
=
$
end
-
$
start
;
$
total
+=
$
last_time
;
$
num
=
number_format
(
$
last_time
,
3
);
$
pad
=
str_repeat
(
"
"
,
24
-
strlen
(
$
name
)-
strlen
(
$
num
));
if
(
is_null
(
$
overhead
)) {
echo
$
name
.
$
pad
.
$
num
.
"\n"
;
}
else
{
$
num2
=
number_format
(
$
last_time
-
$
overhead
,
3
);
echo
$
name
.
$
pad
.
$
num
.
"
"
.
$
num2
.
"\n"
;
}
ob_start
();
return
getmicrotime
();
}
function
total
()
{
global
$
total
;
$
pad
=
str_repeat
(
"
-
"
,
24
);
echo
$
pad
.
"\n"
;
$
num
=
number_format
(
$
total
,
3
);
$
pad
=
str_repeat
(
"
"
,
24
-
strlen
(
"
Total
"
)-
strlen
(
$
num
));
echo
"
Total
"
.
$
pad
.
$
num
.
"\n"
;
}
const
N
=
5000000
;
$
t0
=
$
t
=
start_test
();
empty_loop
(N);
$
t
=
end_test
(
$
t
,
'
empty_loop
'
);
$
overhead
=
$
last_time
;
simpleucall
(N);
$
t
=
end_test
(
$
t
,
'
func()
'
,
$
overhead
);
simpleudcall
(N);
$
t
=
end_test
(
$
t
,
'
undef_func()
'
,
$
overhead
);
simpleicall
(N);
$
t
=
end_test
(
$
t
,
'
int_func()
'
,
$
overhead
);
Foo::
read_static
(N);
$
t
=
end_test
(
$
t
,
'
$x = self::$x
'
,
$
overhead
);
Foo::
write_static
(N);
$
t
=
end_test
(
$
t
,
'
self::$x = 0
'
,
$
overhead
);
Foo::
isset_static
(N);
$
t
=
end_test
(
$
t
,
'
isset(self::$x)
'
,
$
overhead
);
Foo::
empty_static
(N);
$
t
=
end_test
(
$
t
,
'
empty(self::$x)
'
,
$
overhead
);
read_static
(N);
$
t
=
end_test
(
$
t
,
'
$x = Foo::$x
'
,
$
overhead
);
write_static
(N);
$
t
=
end_test
(
$
t
,
'
Foo::$x = 0
'
,
$
overhead
);
isset_static
(N);
$
t
=
end_test
(
$
t
,
'
isset(Foo::$x)
'
,
$
overhead
);
empty_static
(N);
$
t
=
end_test
(
$
t
,
'
empty(Foo::$x)
'
,
$
overhead
);
Foo::
call_static
(N);
$
t
=
end_test
(
$
t
,
'
self::f()
'
,
$
overhead
);
call_static
(N);
$
t
=
end_test
(
$
t
,
'
Foo::f()
'
,
$
overhead
);
$
x
=
new
Foo
();
$
x
->
read_prop
(N);
$
t
=
end_test
(
$
t
,
'
$x = $this->x
'
,
$
overhead
);
$
x
->
write_prop
(N);
$
t
=
end_test
(
$
t
,
'
$this->x = 0
'
,
$
overhead
);
$
x
->
assign_add_prop
(N);
$
t
=
end_test
(
$
t
,
'
$this->x += 2
'
,
$
overhead
);
$
x
->
pre_inc_prop
(N);
$
t
=
end_test
(
$
t
,
'
++$this->x
'
,
$
overhead
);
$
x
->
pre_dec_prop
(N);
$
t
=
end_test
(
$
t
,
'
--$this->x
'
,
$
overhead
);
$
x
->
post_inc_prop
(N);
$
t
=
end_test
(
$
t
,
'
$this->x++
'
,
$
overhead
);
$
x
->
post_dec_prop
(N);
$
t
=
end_test
(
$
t
,
'
$this->x--
'
,
$
overhead
);
$
x
->
isset_prop
(N);
$
t
=
end_test
(
$
t
,
'
isset($this->x)
'
,
$
overhead
);
$
x
->
empty_prop
(N);
$
t
=
end_test
(
$
t
,
'
empty($this->x)
'
,
$
overhead
);
$
x
->
call
(N);
$
t
=
end_test
(
$
t
,
'
$this->f()
'
,
$
overhead
);
$
x
->
read_const
(N);
$
t
=
end_test
(
$
t
,
'
$x = Foo::TEST
'
,
$
overhead
);
create_object
(N);
$
t
=
end_test
(
$
t
,
'
new Foo()
'
,
$
overhead
);
read_const
(N);
$
t
=
end_test
(
$
t
,
'
$x = TEST
'
,
$
overhead
);
read_auto_global
(N);
$
t
=
end_test
(
$
t
,
'
$x = $_GET
'
,
$
overhead
);
read_global_var
(N);
$
t
=
end_test
(
$
t
,
'
$x = $GLOBALS[
\'
v
\'
]
'
,
$
overhead
);
read_hash
(N);
$
t
=
end_test
(
$
t
,
'
$x = $hash[
\'
v
\'
]
'
,
$
overhead
);
read_str_offset
(N);
$
t
=
end_test
(
$
t
,
'
$x = $str[0]
'
,
$
overhead
);
issetor
(N);
$
t
=
end_test
(
$
t
,
'
$x = $a ?: null
'
,
$
overhead
);
issetor2
(N);
$
t
=
end_test
(
$
t
,
'
$x = $f ?: tmp
'
,
$
overhead
);
ternary
(N);
$
t
=
end_test
(
$
t
,
'
$x = $f ? $f : $a
'
,
$
overhead
);
ternary2
(N);
$
t
=
end_test
(
$
t
,
'
$x = $f ? $f : tmp
'
,
$
overhead
);
total
(
$
t0
,
"
Total
"
);
Back
|
FazBrowse Home
|
New Git URL