001/* Copyright (C) Cross The Road Electronics 2024 */
002package com.ctre.phoenix.time;
003
004/**
005 * Stopwatch to track time in milliseconds
006 */
007public class StopWatch
008{
009        private long _t0 = 0;
010        private long _t1 = 0;
011        
012        /**
013         * Start the stopwatch
014         */
015        public void start()
016        {
017                _t0 = System.currentTimeMillis();
018        }
019        
020        /**
021         * @return Current time elapsed since start in s
022         */
023        public double getDuration()
024        {
025                return (double)getDurationMs() / 1000;
026        }
027        /**
028         * @return Current time elapsed since start in ms
029         */
030        public int getDurationMs()
031        {
032                _t1 = System.currentTimeMillis();
033                long retval = _t1 - _t0;
034                if(retval < 0)
035                        retval = 0;
036                return (int)retval;
037        }
038}