Stopwatch Functions

Prev Next

Function Names

watch start, watch stop, watch continue, watch reset, watch read

Description

watch start Returns previous time, resets and starts the watch
watch stop Returns the time and stops the watch.
watch continue Returns the time and lets the watch continue to run
watch reset Returns the time and resets the watch. If the watch was continuing before, then it will continue from zero.
watch read Returns the time. No push-button actions on the watch.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

OS differences

Windows uses wall clock time. Pause applications to measure true performance.
LINUX and MACOS uses actual CPU processing time.

Parameter count

0

Return value

TypeDescription
numeral Stopwatch time in milliseconds elapsed

The watch time will be returned before the indicated action will happen. E.g. watch reset returns the time before the reset operation.

Examples

               watch start;
               sleep (0.05); // 50 ms
               echo( "Started: ", watch read(), " ms" );
               sleep (0.05);
               echo( "Before resetting: ", watch reset() );
               sleep (0.05);
               echo( "Before stopping: ", watch stop() );
               sleep (0.05);
               echo( "Before continuing: ", watch continue() );
               sleep (0.05);
               echo( watch stop(),", ", watch reset(), " and now back at zero: ", watch reset() );

Output

Started: 64 ms
Before resetting: 125
Before stopping: 62
Before continuing: 62
125, 125 and now back at zero: 0
Try it yourself: Open LIB_Function_watch_start.b4p in B4P_Examples.zip. Decompress before use.