SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AbstractChrono.java
1/*
2 * Class: AbstractChrono
3 * Description: calculates CPU time of parts of a program
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util;
26
71public abstract class AbstractChrono {
72
73 private long m_second;
74 private long m_microsec;
75 private long[] now = new long[2];
76
77 // tab[0] = seconds, tab[1] = microseconds
78 protected abstract void getTime(long[] tab);
79
83 public AbstractChrono() {
84 }
85
89 public void init() {
90 getTime(now);
91 m_second = now[0];
92 m_microsec = now[1];
93 }
94
101 public double getSeconds() {
102 getTime(now);
103 double time = (now[1] - m_microsec) / 1000000.0 + (now[0] - m_second);
104 return time;
105 }
106
113 public double getMinutes() {
114 getTime(now);
115 double time = (now[1] - m_microsec) / 1000000.0 + (now[0] - m_second);
116 return time * 1.666666667 * 0.01;
117 }
118
125 public double getHours() {
126 getTime(now);
127 double time = (now[1] - m_microsec) / 1000000.0 + (now[0] - m_second);
128 return time * 2.777777778 * 0.0001;
129 }
130
137 public String format() {
138 return format(getSeconds());
139 }
140
147 public static String format(double time) {
148 int second, hour, min, centieme;
149 hour = (int) (time / 3600.0);
150 if (hour > 0)
151 time -= ((double) hour * 3600.0);
152 min = (int) (time / 60.0);
153 if (min > 0)
154 time -= ((double) min * 60.0);
155 second = (int) time;
156 centieme = (int) (100.0 * (time - (double) second) + 0.5);
157 return String.valueOf(hour) + ":" + min + ":" + second + "." + centieme;
158 }
159
160}
161
double getHours()
Returns the CPU time in hours used by the program since the last call to init for this AbstractChrono...
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
void init()
Initializes this AbstractChrono to zero.
static String format(double time)
Converts the time time, given in seconds, to a String in the HH:MM:SS.xx format.
double getSeconds()
Returns the CPU time in seconds used by the program since the last call to init for this AbstractChro...
double getMinutes()
Returns the CPU time in minutes used by the program since the last call to init for this AbstractChro...