-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.php
More file actions
100 lines (86 loc) · 3 KB
/
benchmark.php
File metadata and controls
100 lines (86 loc) · 3 KB
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
<?php
require_once 'vendor/autoload.php';
use function Epic64\Elem\div;
use function Epic64\Elem\raw;
$iterations = 10000;
echo "=== Bottleneck Analysis (10,000 iterations) ===\n\n";
// Test 1: ElementFactory::createElement directly
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = \Epic64\Elem\ElementFactory::createElement('div');
}
$end = hrtime(true);
echo "ElementFactory::createElement: " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 2: new Element
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = new \Epic64\Elem\Element('div');
}
$end = hrtime(true);
echo "new Element('div'): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 3: div() function
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div();
}
$end = hrtime(true);
echo "div() function: " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 4: div with class
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div(class: 'test');
}
$end = hrtime(true);
echo "div(class: 'test'): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 5: class() method - realistic (few classes per element)
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div();
$el->class('card', 'shadow', 'rounded');
}
$end = hrtime(true);
echo "class() realistic (3 classes): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 5b: class() method - worst case (cumulative adds)
$el = div();
$start = hrtime(true);
for ($i = 0; $i < 1000; $i++) { // Only 1000 iterations for this edge case
$el->class('test' . $i);
}
$end = hrtime(true);
echo "class() cumulative (1k adds): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 6: raw() function - creates temp HTMLDocument
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div()(raw('<span>test</span>'));
}
$end = hrtime(true);
echo "div with raw(): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 7: div with text
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div(text: 'Hello World');
}
$end = hrtime(true);
echo "div with text param: " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 8: Nested structure
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$el = div()(div()(div()));
}
$end = hrtime(true);
echo "Nested div()(div()(div())): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 9: toHtml
$el = div(class: 'parent')(div(class: 'child', text: 'Hello'));
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$html = $el->toHtml();
}
$end = hrtime(true);
echo "toHtml (no pretty): " . number_format(($end - $start) / 1e6, 2) . " ms\n";
// Test 10: toHtml pretty
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$html = $el->toHtml(true);
}
$end = hrtime(true);
echo "toHtml (pretty): " . number_format(($end - $start) / 1e6, 2) . " ms\n";