[js_timer]

Description

Link: [js_timer]
Author: Johan Sölve
Category: Utility
Version: 6.x
License: Public Domain
Posted: Jul. 20, 2006
Updated: Sep. 06, 2006
More by this author...
Create one or more page timers that shows elapsed time when the timer is called.

The timer shows the elapsed time in milliseconds since it was created, or since it was reset.

As default the timer is returned as a formatted string, but it can also be returned as an integer value or as a decimal seconds value.

Works with Lasso 6 and later (maybe also Lasso 5).

Parameters

none


Sample Usage

// create a timer instance
var: 't'=js_timer;

// simulate a lengthy code run
sleep: 1234;

// output the timer as string formatted as "1 234 ms"
$t;

// simulate some more code
sleep: 200;

// output the timer as seconds (decimal value)
$t -> seconds;

// reset the timer
$t -> reset;

// simulate some more code
sleep: 321;

// output the timer as an integer value
$t -> integer;
						

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[
define_type: 'js_timer', 'integer', -prototype;
	local: 'timer'=integer;
	
	define_tag: 'oncreate';
		(self->'timer') = _date_msec;
	/define_tag;
	
	define_tag: 'onconvert';
		local: 'output'=(_date_msec - (self->'timer'));
		#output ->(setformat: -groupchar=' ');
		return: #output + ' ms';
	/define_tag;
	
	define_tag: 'reset';
		(self->'timer') = _date_msec;
	/define_tag;

	define_tag: 'integer';
		return: (_date_msec - (self->'timer'));
	/define_tag;

	define_tag: 'seconds';
		return: (_date_msec - (self->'timer')) / 1000.0;
	/define_tag;

/define_type;


]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular