00001 package edu.tum.cs.util; 00002 00003 public class Stopwatch { 00004 00005 private long startTime = 0; 00006 private long stopTime = 0; 00007 private long elapsed = 0; 00008 private boolean running = false; 00009 00010 public void start() { 00011 this.running = true; 00012 this.startTime = System.currentTimeMillis(); 00013 } 00014 00015 public void stop() { 00016 this.stopTime = System.currentTimeMillis(); 00017 this.running = false; 00018 elapsed += stopTime - startTime; 00019 } 00020 00025 public long getElapsedTime() { 00026 if(running) 00027 return elapsed + System.currentTimeMillis() - startTime; 00028 else 00029 return elapsed; 00030 } 00031 00036 public double getElapsedTimeSecs() { 00037 return (double)getElapsedTime() / 1000; 00038 } 00039 }