Lasso Soft Inc. > Home

[timer]

Linktimer
AuthorJason Huck
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted15 Feb 2008
Updated17 Feb 2008
More by this author...

Description

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
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;

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.

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' = '
		
		
\ '); 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

Comments

17 Feb 2008, Jason Huck

Updated

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