-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy path80_benchmark.php
84 lines (65 loc) · 2.9 KB
/
80_benchmark.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
<?php
/*
Below are a few informal benchmarks, meant to be run in CLI or web. Loading the parser and renderer
represents the worst case scenario of parsing or rendering a text in a webserver with no opcode
cache. The first parsing and rendering measures the time it takes to load extra plugins and set up
the internal data structures. All subsequent parsings and renderings should be faster than the
first. Parsing and rendering plain text is a special case that uses code optimized for this task. In
general, whether it's blogs or forums a majority of user content is plain text with no HTML, BBCodes
or emoticons.
All times are expressed in microseconds. (1/1,000,000th of a second)
*/
include __DIR__ . '/../../vendor/autoload.php';
use s9e\TextFormatter\Bundles\Forum as TextFormatter;
if (php_sapi_name() !== 'cli')
{
echo '<pre>';
}
echo "All times are expressed in microseconds. (1 millionth of a second)\n\n";
$t1 = microtime(true);
TextFormatter::getParser();
$t2 = microtime(true);
TextFormatter::getRenderer();
$t3 = microtime(true);
printf("%6s µs - Loading parser\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Loading renderer\n", round(1000000 * ($t3 - $t2)));
$text = 'Hello, [i]world[/i] :)';
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing rich text for the first time\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering rich text for the first time\n", round(1000000 * ($t3 - $t2)));
$text = 'Hello, [i]world[/i] :)';
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing rich text for the second time\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering rich text for the second time\n", round(1000000 * ($t3 - $t2)));
$text = 'Hello, world!';
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing plain text\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering plain text\n", round(1000000 * ($t3 - $t2)));
$text = str_repeat("A line of [b]rich[/b] text\n", 200);
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing 200 lines of rich text\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering 200 lines of rich text\n", round(1000000 * ($t3 - $t2)));
$text = str_repeat(":) ", 1000);
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing 1000 emoticons\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering 1000 emoticons\n", round(1000000 * ($t3 - $t2)));