function::read_stopwatch_ms - Linux
Overview
read_stopwatch_ms
retrieves and prints the elapsed time in milliseconds from a stopwatch created by the start_stopwatch
function. It is useful for measuring and logging elapsed time in scripts and programs.
Syntax
read_stopwatch_ms [OPTIONS] <STOPWATCH_KEY>
Options/Flags
- -h, –help: Display usage information and exit.
- -r, –raw: Print only the elapsed time in milliseconds without any formatting.
Examples
Simple Example:
start_stopwatch stopwatch_example_1
sleep 2
read_stopwatch_ms stopwatch_example_1
Output:
2000
Example with Formatting:
read_stopwatch_ms -r stopwatch_example_1
Output:
2000
Common Issues
- Stopwatch key not found: Ensure that the specified
STOPWATCH_KEY
was previously created using thestart_stopwatch
function. - Negative elapsed time: The stopwatch may have been reset or not started properly.
Integration
read_stopwatch_ms
can be combined with other commands for logging and monitoring purposes. For example:
start_stopwatch stopwatch_example_2
# Perform some tasks
read_stopwatch_ms stopwatch_example_2 | logger
Related Commands
start_stopwatch
: Creates a stopwatch to measure elapsed time.reset_stopwatch
: Resets the elapsed time of a stopwatch.stop_stopwatch
: Stops the measurement of elapsed time for a stopwatch.