rah_runtime
Published under current TXP projects
Rah_runtime returns runtimes from point A to B in microseconds. The plugin can be used to diagnose runtimes of specific blocks of Textpattern’s markup code.
Image: rah_runtime
Requirements
- Textpattern 4.x.x+
Installation and usage
The general behavior stands:
- Go to your Textpattern installation’s admin panel.
- Navigate to Admin / Plugins.
- Download and open the plugin code.
- Copy the plugin code to the install plugin box.
- Click install and go thru the automated installation process.
- After installation find the plugin from the plugin list and click Activate.
- Now the plugin is installed and ready to be used.
Attributes
The tag is <txp:rah_runtime /> and attributes for it follow.
index
With this attribute you can nest several tag pairs and count several independent runtimes.
Example: index="1" Default: "0"
format
Return formated version of the time. Will make the time respect power of ten, and SI units smaller than microsends won’t be returned, just microsends with decimals. By default, used (1).
Example: format="0" Default: "1"
persistent
If set to 1, the runtime is kept alive after outputting the time. Normally the runtime pair is destroyed after using it, but with persistent the initial runtime is still usable. The attribute is useful, if you want to calculate multiple runtimes from same single starting point.
Example: persistent="1" Default: "0"
Examples
Simple usage:
<txp:rah_runtime />
<!--
Some code here, for example:
<txp:article />
-->
Runtime: <txp:rah_runtime />
Returns: [...] Runtime: 0.000011
Using multiple nested tag pairs:
<txp:rah_runtime index="2" />
<txp:rah_runtime index="1" />
Time1: <txp:rah_runtime index="1" />
Time2: <txp:rah_runtime index="2" />
Returns: Time1: 0.000081 Time2: 0.000184
Using persistent runtimes:
<!--
Start the runtime timer
-->
<txp:rah_runtime persistent="1" />
<!--
Some code here, for example:
<txp:article />
-->
<!--
Output runtime
-->
<txp:rah_runtime persistent="1" />
<!--
Some more code here, for example:
<txp:article />
-->
<!--
Output runtime, calculated
from the same original starting point
-->
<txp:rah_runtime persistent="1" />
<!--
Even some more code.
-->
<!--
Destroy and output the final runtime,
calculated from the same original starting point
-->
<txp:rah_runtime />
Note that every one of the tags has persistent attribute. If the tag doesn’t have it, then the runtime pair is destroyed after outputting it. To finally destroy the runtime, set persistent to "0" (zero) or remove the attribute.
Changelog
Version 0.3
- Added: a new attribute
persistent. Disables destroying of used runtime pairs. - Changed: Now stores the runtimes in a static variable instead of a global.
Version 0.2
- Fixed: now returns as float (compatible with pre-PHP5). Thank you for reporting, Andreas.
Version 0.1
- First release