Skip to content

Commit 19fb8ca

Browse files
committed
Readd benchmark
1 parent 9b63691 commit 19fb8ca

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

ext/uri/tests/001.phpt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
--TEST--
2+
Parse URL
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$t1 = hrtime(true);
9+
for ($i = 0; $i < 1000; $i++) {
10+
Uri\Rfc3986\Uri::parse("https://example.com/");
11+
}
12+
$t2 = hrtime(true);
13+
14+
$t3 = hrtime(true);
15+
for ($i = 0; $i < 1000; $i++) {
16+
Uri\WhatWg\Url::parse("https://example.com/");
17+
}
18+
$t4 = hrtime(true);
19+
20+
$t5 = hrtime(true);
21+
for ($i = 0; $i < 1000; $i++) {
22+
parse_url("https://example.com/");
23+
}
24+
$t6 = hrtime(true);
25+
26+
echo "RFC 3986 parser: https://example.com/\n";
27+
var_dump(($t2 - $t1) / 1_000_000_000);
28+
var_dump(Uri\Rfc3986\Uri::parse("https://example.com/"));
29+
echo "------------------------\n";
30+
31+
echo "WHATWG parser: https://example.com/\n";
32+
var_dump(($t4 - $t3) / 1_000_000_000);
33+
var_dump(Uri\WhatWg\Url::parse("https://example.com"));
34+
echo "------------------------\n";
35+
36+
echo "PHP parser: https://example.com/\n";
37+
var_dump(($t6 - $t5) / 1_000_000_000);
38+
var_dump(parse_url("https://example.com"));
39+
echo "------------------------\n";
40+
41+
?>
42+
--EXPECTF--
43+
RFC 3986 parser: https://example.com/
44+
float(0.0032325)
45+
object(Uri\Rfc3986\Uri)#%d (%d) {
46+
["scheme"]=>
47+
string(5) "https"
48+
["userinfo"]=>
49+
NULL
50+
["username"]=>
51+
NULL
52+
["password"]=>
53+
NULL
54+
["host"]=>
55+
string(11) "example.com"
56+
["port"]=>
57+
NULL
58+
["path"]=>
59+
string(1) "/"
60+
["query"]=>
61+
NULL
62+
["fragment"]=>
63+
NULL
64+
}
65+
------------------------
66+
WHATWG parser: https://example.com/
67+
float(0.004510875)
68+
object(Uri\WhatWg\Url)#%d (%d) {
69+
["scheme"]=>
70+
string(5) "https"
71+
["username"]=>
72+
NULL
73+
["password"]=>
74+
NULL
75+
["host"]=>
76+
string(11) "example.com"
77+
["port"]=>
78+
NULL
79+
["path"]=>
80+
string(1) "/"
81+
["query"]=>
82+
NULL
83+
["fragment"]=>
84+
NULL
85+
}
86+
------------------------
87+
PHP parser: https://example.com/
88+
float(0.004519541)
89+
array(%d) {
90+
["scheme"]=>
91+
string(5) "https"
92+
["host"]=>
93+
string(11) "example.com"
94+
}
95+
------------------------

ext/uri/tests/002.phpt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
--TEST--
2+
Parse URL
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$t1 = hrtime(true);
9+
for ($i = 0; $i < 1000; $i++) {
10+
Uri\Rfc3986\Uri::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists");
11+
}
12+
$t2 = hrtime(true);
13+
14+
$t3 = hrtime(true);
15+
for ($i = 0; $i < 1000; $i++) {
16+
Uri\WhatWg\Url::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists");
17+
}
18+
$t4 = hrtime(true);
19+
20+
$t5 = hrtime(true);
21+
for ($i = 0; $i < 1000; $i++) {
22+
parse_url("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists");
23+
}
24+
$t6 = hrtime(true);
25+
26+
echo "RFC 3986 parser:\n";
27+
var_dump(($t2 - $t1) / 1_000_000_000);
28+
var_dump(Uri\Rfc3986\Uri::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists"));
29+
echo "------------------------\n";
30+
31+
echo "WHATWG parser:\n";
32+
var_dump(($t4 - $t3) / 1_000_000_000);
33+
var_dump(Uri\WhatWg\Url::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists"));
34+
echo "------------------------\n";
35+
36+
echo "parse_url:\n";
37+
var_dump(($t6 - $t5) / 1_000_000_000);
38+
var_dump(parse_url("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists"));
39+
echo "------------------------\n";
40+
41+
?>
42+
--EXPECTF--
43+
RFC 3986 parser:
44+
float(0.004389959)
45+
object(Uri\Rfc3986\Uri)#%d (%d) {
46+
["scheme"]=>
47+
string(5) "https"
48+
["userinfo"]=>
49+
string(17) "username:password"
50+
["username"]=>
51+
string(8) "username"
52+
["password"]=>
53+
string(8) "password"
54+
["host"]=>
55+
string(14) "www.google.com"
56+
["port"]=>
57+
int(8080)
58+
["path"]=>
59+
string(30) "/pathname1/pathname2/pathname3"
60+
["query"]=>
61+
string(10) "query=true"
62+
["fragment"]=>
63+
string(11) "hash-exists"
64+
}
65+
------------------------
66+
WHATWG parser:
67+
float(0.007400166)
68+
object(Uri\WhatWg\Url)#%d (%d) {
69+
["scheme"]=>
70+
string(5) "https"
71+
["username"]=>
72+
string(8) "username"
73+
["password"]=>
74+
string(8) "password"
75+
["host"]=>
76+
string(14) "www.google.com"
77+
["port"]=>
78+
int(8080)
79+
["path"]=>
80+
string(30) "/pathname1/pathname2/pathname3"
81+
["query"]=>
82+
string(10) "query=true"
83+
["fragment"]=>
84+
string(11) "hash-exists"
85+
}
86+
------------------------
87+
parse_url:
88+
float(0.007400166)
89+
array(%d) {
90+
["scheme"]=>
91+
string(5) "https"
92+
["host"]=>
93+
string(14) "www.google.com"
94+
["port"]=>
95+
int(8080)
96+
["user"]=>
97+
string(8) "username"
98+
["pass"]=>
99+
string(8) "password"
100+
["path"]=>
101+
string(30) "/pathname1/pathname2/pathname3"
102+
["query"]=>
103+
string(10) "query=true"
104+
["fragment"]=>
105+
string(11) "hash-exists"
106+
}
107+
------------------------

0 commit comments

Comments
 (0)