Lasso Soft Inc. > Home


AuthorJason Huck
LicensePublic Domain
Posted15 Feb 2008
Updated17 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.

Sample Usage

// start the timer
var('debug') = true;
timer('started timer');

// do some stuff

// set a marker
timer('did some stuff');

// do more stuff

// set another marker
timer('did some more stuff');

// display results

Source Code

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.

	-opt='note', -type='string',
	-opt='collect', -type='boolean',
	-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.');	

	-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' = '
\ '); iterate($__timerstats, local('i')); local('w') = percent(decimal(#i->second) / decimal(#total)); #out += ' \ '; /iterate; #out += '
Marker Percent Total Time (ms)
' + #i->first + '
' + #w + '
' + #i->second + '
Total ' + #total + '
'; return(#out); /define_tag;

Related Tags


17 Feb 2008, Jason Huck


Per request, [timerstats] now explicitly checks for $debug to be true rather than relying on whether or not [timer] has collected any data.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft