Link | timer |
Author | Jason Huck |
Category | Utility |
Version | 8.5.x |
License | Public Domain |
Posted | 15 Feb 2008 |
Updated | 17 Feb 2008 |
More by this author... |
This is yet another set of tags which allows you to set markers in your scripts and return the elapsed times between them. This version consists of two tags, [timer] and [timerstats], and works as follows:
You place markers in your code by calling [timer] with an optional note/label. You must set at least one "starter" timer before the first event you wish to time. If you want to see the results immediately, you may set the -collect param to false. Otherwise each duration is collected and displayed when [timerstats] is called.
Both tags require a page variable called 'debug' to be set to true, otherwise they immediately return null, so it's okay to leave your markers in place.
The [timerstats] tag returns a table showing each marker and the elapsed time both in milliseconds and as a percentage of the total (which is also shown). Percentages are represented as a CSS bar graph. The CSS is embedded within the tag for portability.
// start the timer var('debug') = true; timer('started timer'); // do some stuff sleep(200); // set a marker timer('did some stuff'); // do more stuff sleep(100); // set another marker timer('did some more stuff'); // display results timerstats;
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag( 'timer', -opt='note', -type='string', -opt='collect', -type='boolean', -priority='replace', -encodenone, -description='Generates a list of timed events.' ); !var_defined('debug') || !$debug ? return; !var_defined('__timerstart') ? var('__timerstart') = date_msec; !var_defined('__timer') ? var('__timer') = 0; !var_defined('__timerstats') ? var('__timerstats' = array); !local_defined('note') ? local('note') = ''; !local_defined('collect') ? local('collect') = true; local('now') = date_msec; local('elapsed') = ($__timer == 0 ? 0 | #now - $__timer); #collect ? $__timer = #now; #collect ? $__timerstats->insert(#note = #elapsed) | return(#note + ': ' + #elapsed + 'ms.'); /define_tag; define_tag( 'timerstats', -priority='replace', -encodenone, -description='Displays any timed events collected on the current page.' ); !var_defined('debug') || !$debug ? return; !var_defined('__timerstats') ? return; local('total') = (date_msec - $__timerstart); local('out' = '
Marker | Percent Total | Time (ms) |
---|---|---|
' + #i->first + ' | ' + #i->second + ' | |
Total | ' + #total + ' |
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Updated