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