Every now and then I want to use a file_read to include a static .html file on my site, and I always wonder if that might slow things down, especially if I'm doing it globally. Today I started tinkering with using a static .html instead of the category tree. There's a minor difference in page load time between the two, with static .html being faster, and I'm wondering if my test could be flawed in some way. If it's accurate, then I'm wondering why. Anyone have any ideas?
In general, using the category tree seemed to take around 800 microseconds, and using a static .html took around 100.
Here's how I tested:
top of head tag content (saves the page start time and current time, and creates a results variable which will be appended to and eventually displayed in the footer)
global header (decides between category tree or static include based on query string flag, marks the moment before and after)
bottom of global footer (prints results)
Output when using category tree:
Output when using static .html:
In general, using the category tree seemed to take around 800 microseconds, and using a static .html took around 100.
Here's how I tested:
top of head tag content (saves the page start time and current time, and creates a results variable which will be appended to and eventually displayed in the footer)
Code:
<mvt:if expr="NOT ISNULL g.mivaBenchmark"> <mvt:assign name="benchmarkResults" value="''" /> <mvt:assign name="benchmarkPageStart" value="s.dyn_tm_usec" /> <mvt:assign name="benchmarkLast" value="g.benchmarkPageStart" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>benchmarkPageStart = ' $ g.benchmarkPageStart" /> </mvt:if>
Code:
<mvt:if expr="NOT ISNULL g.mivaBenchmark"> <mvt:assign name="benchmarkCurrentTime" value="s.dyn_tm_usec" /> <mvt:assign name="benchmarkTimeSinceLast" value="g.benchmarkCurrentTime - g.benchmarkLast" /> <mvt:assign name="benchmarkLast" value="g.benchmarkCurrentTime" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>before category tree:'" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkTimeSinceLast = ' $ g.benchmarkTimeSinceLast" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkCurrentTime = ' $ g.benchmarkCurrentTime" /> </mvt:if> <mvt:if expr="NOT ISNULL g.mivaTestUseCatTree"> <mvt:item name="category_tree" /> <mvt:else> <mvt:assign name="leftnavResult" value="file_read( '/path/to/my/leftnav.html', 'script', g.leftnav )" /> &mvt:global:leftnav; </mvt:if> <mvt:if expr="NOT ISNULL g.mivaBenchmark"> <mvt:assign name="benchmarkCurrentTime" value="s.dyn_tm_usec" /> <mvt:assign name="benchmarkTimeSinceLast" value="g.benchmarkCurrentTime - g.benchmarkLast" /> <mvt:assign name="benchmarkLast" value="g.benchmarkCurrentTime" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>after leftnav:'" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkTimeSinceLast = ' $ g.benchmarkTimeSinceLast" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkCurrentTime = ' $ g.benchmarkCurrentTime" /> </mvt:if>
Code:
<mvt:if expr="NOT ISNULL g.mivaBenchmark"> <mvt:assign name="benchmarkCurrentTime" value="s.dyn_tm_usec" /> <mvt:assign name="benchmarkTimeSinceLast" value="g.benchmarkCurrentTime - g.benchmarkLast" /> <mvt:assign name="benchmarkTimeSinceStart" value="g.benchmarkCurrentTime - g.benchmarkPageStart" /> <mvt:assign name="benchmarkLast" value="g.benchmarkCurrentTime" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>page complete:'" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkTimeSinceLast = ' $ g.benchmarkTimeSinceLast" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkTimeSinceStart = ' $ g.benchmarkTimeSinceStart" /> <mvt:assign name="benchmarkResults" value="g.benchmarkResults $ '<br>--benchmarkCurrentTime = ' $ g.benchmarkCurrentTime" /> <div style="border: 1px solid #000; margin: 20px; padding: 20px; position: absolute; width: 80%; background-color: #fff; z-index: 999999999;"> &mvt:global:benchmarkResults; </div> </mvt:if>
Code:
benchmarkPageStart = 772249 before leftnav: --benchmarkTimeSinceLast = 16798 --benchmarkCurrentTime = 789047 after leftnav: --benchmarkTimeSinceLast = 834 --benchmarkCurrentTime = 789881 page complete: --benchmarkTimeSinceLast = 717 --benchmarkTimeSinceStart = 18349 --benchmarkCurrentTime = 790598
Code:
benchmarkPageStart = 790250 before leftnav: --benchmarkTimeSinceLast = 16828 --benchmarkCurrentTime = 807078 after leftnav: --benchmarkTimeSinceLast = 131 --benchmarkCurrentTime = 807209 page complete: --benchmarkTimeSinceLast = 725 --benchmarkTimeSinceStart = 17684 --benchmarkCurrentTime = 807934
Comment