diff --git a/README.md b/README.md index 921e257..ec181ca 100644 --- a/README.md +++ b/README.md @@ -75,17 +75,36 @@ Output: ``` -## Details +## Performance -See [8fold XML Builder](https://github.com/8fold/php-xml-builder#readme) for -details. +The `/comparisons` folder can be used to run performance tests locally to compare the same output using: + +1. straight HTML, +2. standard PHP, +3. PHP HTML Builder alongside standard PHP (the Element class), +4. PHP HTML Builder only (the Document class), and +5. PHP HTML Builder only using PSR-4 autoloading. + +These results are from February 26th, 2024: -## Usage (advanced) +|Configuration |Average time in milliseconds |Median time in milliseconds | +|:---|---:|---:| +|1 |0.0399683 |0.0017415 | +|2 |0.0953241 |0.0160480 | +|3 |1.6026525 |1.4603320 | +|4 |1.7849769 |1.7918970 | +|5 |8.9957415 |8.8755520 | -TODO +Things worth noting (as rough interpretations): -HTML Builder has the ability to help create valid HTML documents based on the -HTML specification. +1. PHP being used as a template engine has a negligible impact on speed. +2. Using `require_once` without PSR-4 autoloading decreases speed by roughly 1 millisecond; however, once the code is made available, very little additional cost seems to be present. +3. Using PSR-4 decreases speed by roughly 6 milliseconds; however, ensures everything is present and available. + +## Details + +See [8fold XML Builder](https://github.com/8fold/php-xml-builder#readme) for more +details. ## Other diff --git a/comparisons/html/index.php b/comparisons/html/index.php new file mode 100644 index 0000000..5a58093 --- /dev/null +++ b/comparisons/html/index.php @@ -0,0 +1,74 @@ + + + +
+Brief description of content for blog post 1
+ +Brief description of content for blog post 2
+ +Brief description of content for blog post 3
+ +Brief description of content for blog post 4
+ +Brief description of content for blog post 5
+ +Brief description of content for blog post 6
+ +Brief description of content for blog post 7
+ +Brief description of content for blog post 8
+ +Brief description of content for blog post 9
+ +Brief description of content for blog post 10
+ +' . $ms . 'ms
'); +?> diff --git a/comparisons/php-html-builder-document/index.php b/comparisons/php-html-builder-document/index.php new file mode 100644 index 0000000..8bb82a3 --- /dev/null +++ b/comparisons/php-html-builder-document/index.php @@ -0,0 +1,133 @@ + "Blog title 1", + "description" => "Brief description for blog post 1", + "url" => [ + "href" => "#", + "text" => "Read blog post 1" + ] + ], + [ + "title" => "Blog title 2", + "description" => "Brief description for blog post 2", + "url" => [ + "href" => "#", + "text" => "Read blog post 2" + ] + ], + [ + "title" => "Blog title 3", + "description" => "Brief description for blog post 3", + "url" => [ + "href" => "#", + "text" => "Read blog post 3" + ] + ], + [ + "title" => "Blog title 4", + "description" => "Brief description for blog post 4", + "url" => [ + "href" => "#", + "text" => "Read blog post 4" + ] + ], + [ + "title" => "Blog title 5", + "description" => "Brief description for blog post 5", + "url" => [ + "href" => "#", + "text" => "Read blog post 5" + ] + ], + [ + "title" => "Blog title 6", + "description" => "Brief description for blog post 6", + "url" => [ + "href" => "#", + "text" => "Read blog post 6" + ] + ], + [ + "title" => "Blog title 7", + "description" => "Brief description for blog post 7", + "url" => [ + "href" => "#", + "text" => "Read blog post 7" + ] + ], + [ + "title" => "Blog title 8", + "description" => "Brief description for blog post 8", + "url" => [ + "href" => "#", + "text" => "Read blog post 8" + ] + ], + [ + "title" => "Blog title 9", + "description" => "Brief description for blog post 9", + "url" => [ + "href" => "#", + "text" => "Read blog post 9" + ] + ], + [ + "title" => "Blog title 10", + "description" => "Brief description for blog post 10", + "url" => [ + "href" => "#", + "text" => "Read blog post 10" + ] + ] +]; + +$sections = []; +foreach ($posts as $post) { + $sections[] = \Eightfold\HTMLBuilder\Element::section( + \Eightfold\HTMLBuilder\Element::h2($post['title']), + \Eightfold\HTMLBuilder\Element::p($post['description']), + \Eightfold\HTMLBuilder\Element::p( + \Eightfold\HTMLBuilder\Element::a($post['url']['text']) + ->props('href ' . $post['url']['href']) + ) + ); +} + +print \Eightfold\HTMLBuilder\Document::create( + $pageTitle +)->body( + \Eightfold\HTMLBuilder\Element::h1($pageTitle), + \Eightfold\HTMLBuilder\Element::a('time')->props('href #bottom'), + \Eightfold\HTMLBuilder\Element::article(...$sections) +); + +$end = hrtime(true); + +$elapsed = $end - $start; +$ms = $elapsed/1e+6; + +print('' . $ms . 'ms
'); +?> diff --git a/comparisons/php-html-builder-element/index.php b/comparisons/php-html-builder-element/index.php new file mode 100644 index 0000000..126045a --- /dev/null +++ b/comparisons/php-html-builder-element/index.php @@ -0,0 +1,138 @@ + "Blog title 1", + "description" => "Brief description for blog post 1", + "url" => [ + "href" => "#", + "text" => "Read blog post 1" + ] + ], + [ + "title" => "Blog title 2", + "description" => "Brief description for blog post 2", + "url" => [ + "href" => "#", + "text" => "Read blog post 2" + ] + ], + [ + "title" => "Blog title 3", + "description" => "Brief description for blog post 3", + "url" => [ + "href" => "#", + "text" => "Read blog post 3" + ] + ], + [ + "title" => "Blog title 4", + "description" => "Brief description for blog post 4", + "url" => [ + "href" => "#", + "text" => "Read blog post 4" + ] + ], + [ + "title" => "Blog title 5", + "description" => "Brief description for blog post 5", + "url" => [ + "href" => "#", + "text" => "Read blog post 5" + ] + ], + [ + "title" => "Blog title 6", + "description" => "Brief description for blog post 6", + "url" => [ + "href" => "#", + "text" => "Read blog post 6" + ] + ], + [ + "title" => "Blog title 7", + "description" => "Brief description for blog post 7", + "url" => [ + "href" => "#", + "text" => "Read blog post 7" + ] + ], + [ + "title" => "Blog title 8", + "description" => "Brief description for blog post 8", + "url" => [ + "href" => "#", + "text" => "Read blog post 8" + ] + ], + [ + "title" => "Blog title 9", + "description" => "Brief description for blog post 9", + "url" => [ + "href" => "#", + "text" => "Read blog post 9" + ] + ], + [ + "title" => "Blog title 10", + "description" => "Brief description for blog post 10", + "url" => [ + "href" => "#", + "text" => "Read blog post 10" + ] + ] +]; + +$sections = []; +foreach ($posts as $post) { + $sections[] = \Eightfold\HTMLBuilder\Element::section( + \Eightfold\HTMLBuilder\Element::h2($post['title']), + \Eightfold\HTMLBuilder\Element::p($post['description']), + \Eightfold\HTMLBuilder\Element::p( + \Eightfold\HTMLBuilder\Element::a($post['url']['text']) + ->props('href ' . $post['url']['href']) + ) + ); +} + +?> + + + +