There's an advanced example in
this topic.
Regardless of features, there's no need to manually keep track of time, the hardware clock in your computer already does that for you.
Here's a basic example(functionality wise):
Stopwatch startSet decimal [startTime] value to the converted value of {DATETICKS}
Stopwatch intervalSet decimal [intervaltoprocess] value to the converted value of {EXP: {DATETICKS} - {DEC:startTime}}
Inline C# Function: Ticks to Human Readable Time, wait until execution finishes
Write '[Blue] Time elapsed: {INT:intervalHours}:{INT:intervalMinutes}:{INT:intervalSeconds}' to log
Where "Ticks to Human Readable Time" contains:
using System;
public class VAInline
{
public void main()
{
TimeSpan interval = TimeSpan.FromTicks(Convert.ToInt64(VA.GetDecimal("intervaltoprocess")));
VA.SetInt("intervalHours", interval.Hours);
VA.SetInt("intervalMinutes", interval.Minutes);
VA.SetInt("intervalSeconds", interval.Seconds);
}
}
The inline function means you don't have to reinvent the wheel to get back from ticks to human readable time.
I'm using regular integers to both save on casting them, and because Gary has considered getting rid of small integers at some point in the future(with backwards compatibility intact no doubt, but better to start early I figure).
One big benefit of using a static starting point is that there's nothing running in the background to keep track of time(that isn't always running when your computer's plugged in), and if you save the value somewhere, you can shut down your computer entirely, and you can still get the elapsed time from that value.
To "reset" the stopwatch, all you need to do is use "Stopwatch start" again to change the starting point.