Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/shared/Timer.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package shared; | |
2 | |
3 import java.io.PrintStream; | |
4 import java.util.Locale; | |
5 | |
6 public class Timer { | |
7 | |
8 public Timer(){this(System.err, true);} | |
9 | |
10 public Timer(String s){ | |
11 this(System.err, true); | |
12 if(outstream!=null){outstream.println(s);} | |
13 } | |
14 | |
15 public Timer(PrintStream outstream_, boolean addTab_){ | |
16 outstream=outstream_; | |
17 addTab=addTab_; | |
18 start(); | |
19 } | |
20 | |
21 public long start(String s){ | |
22 if(outstream!=null){outstream.println(s);} | |
23 return start(); | |
24 } | |
25 | |
26 public long stopAndPrint(){ | |
27 long x=stop(); | |
28 if(outstream!=null){outstream.println(this);} | |
29 return x; | |
30 } | |
31 | |
32 public long stop(String s){ | |
33 long x=stop(); | |
34 if(addTab && s!=null && !s.endsWith("\t")){s=s+"\t";} | |
35 if(outstream!=null){outstream.println(s+this);} | |
36 return x; | |
37 } | |
38 | |
39 public long start(){ | |
40 time1=time2=System.nanoTime(); | |
41 elapsed=0; | |
42 return time1; | |
43 } | |
44 | |
45 public long stop(){ | |
46 time2=System.nanoTime(); | |
47 elapsed=time2-time1; | |
48 return time2; | |
49 } | |
50 | |
51 @Override | |
52 public String toString(){ | |
53 return timeInSeconds(3)+" seconds."; | |
54 } | |
55 | |
56 public String timeInSeconds(int decimals) { | |
57 return String.format(Locale.ROOT, "%."+decimals+"f", timeInSeconds()); | |
58 } | |
59 | |
60 public double timeInSeconds() { | |
61 return elapsed/1000000000d; | |
62 } | |
63 | |
64 public long time1; | |
65 public long time2; | |
66 /** in nanos */ | |
67 public long elapsed; | |
68 | |
69 public PrintStream outstream=System.err; | |
70 public boolean addTab=true; | |
71 } |