From a1080a7bd29016e7038cf739ca98451543d5c3bc Mon Sep 17 00:00:00 2001
From: Josh Bruce
Date: Mon, 26 Feb 2024 18:31:22 -0500
Subject: [PATCH] add: Performance tests
---
README.md | 33 ++++-
comparisons/html/index.php | 74 ++++++++++
comparisons/index.php | 21 +++
.../php-html-builder-document-psr4/index.php | 122 ++++++++++++++++
.../php-html-builder-document/index.php | 133 +++++++++++++++++
.../php-html-builder-element/index.php | 138 ++++++++++++++++++
comparisons/php/index.php | 116 +++++++++++++++
7 files changed, 630 insertions(+), 7 deletions(-)
create mode 100644 comparisons/html/index.php
create mode 100644 comparisons/index.php
create mode 100644 comparisons/php-html-builder-document-psr4/index.php
create mode 100644 comparisons/php-html-builder-document/index.php
create mode 100644 comparisons/php-html-builder-element/index.php
create mode 100644 comparisons/php/index.php
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 @@
+
+
+
+
+ Page title here
+
+
+
+ Page title here
+ time
+
+
+ Blog title 1
+ Brief description of content for blog post 1
+ Read blog post 1
+
+
+ Blog title 2
+ Brief description of content for blog post 2
+ Read blog post 2
+
+
+ Blog title 3
+ Brief description of content for blog post 3
+ Read blog post 3
+
+
+ Blog title 4
+ Brief description of content for blog post 4
+ Read blog post 4
+
+
+ Blog title 5
+ Brief description of content for blog post 5
+ Read blog post 5
+
+
+ Blog title 6
+ Brief description of content for blog post 6
+ Read blog post 6
+
+
+ Blog title 7
+ Brief description of content for blog post 7
+ Read blog post 7
+
+
+ Blog title 8
+ Brief description of content for blog post 8
+ Read blog post 8
+
+
+ Blog title 9
+ Brief description of content for blog post 9
+ Read blog post 9
+
+
+ Blog title 10
+ Brief description of content for blog post 10
+ Read blog post 10
+
+
+' . $ms . 'ms
');
+?>
+
+
diff --git a/comparisons/index.php b/comparisons/index.php
new file mode 100644
index 0000000..a355d6f
--- /dev/null
+++ b/comparisons/index.php
@@ -0,0 +1,21 @@
+
+ Start PHP server and point to `/comparisons`
+ Launch browser to the root address
+ Click link of page to be tested
+ Note displayed render time in milliseconds
+ Refresh browser 11 times; making not of render times (should result in 12 times)
+ Calculate average and median
+
+
+ Plain HTML
+ Has minimal PHP for measuring time
+ PHP
+ Replicates the Plain HTML using common patterns using PHP as a template engine.
+ PHP HTML Builder (element)
+ Replicates the PHP variant using PHP HTML Builder Element to generate the `article` and `section` elements. Does not use Composer autoloading.
+ PHP HTML Builder (document)
+ Replicates the PHP variant using PHP HTML Builder Document to generate the whole HTML output. Does not use Composer autoloading.
+ PHP HTML Builder (document) w/ PSR-4
+ Replicates the PHP HTML Builder (document) variant using PSR-4 autoloading via Composer.
+
+
diff --git a/comparisons/php-html-builder-document-psr4/index.php b/comparisons/php-html-builder-document-psr4/index.php
new file mode 100644
index 0000000..5ccbc1a
--- /dev/null
+++ b/comparisons/php-html-builder-document-psr4/index.php
@@ -0,0 +1,122 @@
+ "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-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'])
+ )
+ );
+}
+
+?>
+
+
+
+
+
+
+
+
+ time
+
+' . $ms . 'ms ');
+?>
+
+
diff --git a/comparisons/php/index.php b/comparisons/php/index.php
new file mode 100644
index 0000000..b218b0c
--- /dev/null
+++ b/comparisons/php/index.php
@@ -0,0 +1,116 @@
+ "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"
+ ]
+ ]
+];
+?>
+
+
+
+
+
+
+
+
+ time
+
+
+
+
+
+' . $ms . 'ms ');
+?>
+
+