Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdline_options_tester/src/Stopwatch.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2004, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
import java.util.*;
24
import java.io.*;
25
import java.text.*;
26
27
/**
28
* STOP watch to calculate time spent in milliseconds in each test
29
* ToDo: Move to System.nanoTime() instead of System.currentTimeMillis() once test source
30
* is built with 1.5 or higher.
31
* Currently millisecond calculation entirely depends on OS update of timer values
32
* which happens only once in few tens of milliseconds. So getting millisecond directly from os may
33
* not be accurate.
34
*
35
*/
36
public class Stopwatch {
37
38
private long startTime = -1;
39
private long stopTime = -1;
40
private boolean running = false;
41
private Calendar calendar = Calendar.getInstance();
42
TimeZone timeZone = calendar.getTimeZone();
43
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
44
45
public Stopwatch start() {
46
System.out.println("Test start time: " + df.format(calendar.getTime()) + " " + timeZone.getDisplayName());
47
startTime = System.currentTimeMillis();
48
running = true;
49
return this;
50
}
51
52
public Stopwatch stop() {
53
stopTime = System.currentTimeMillis();
54
running = false;
55
return this;
56
}
57
58
/** getTimeSpent will return the elapsed time in milliseconds
59
* if the watch has never been started then return zero
60
*/
61
public long getTimeSpent() {
62
if (startTime == -1) {
63
return 0;
64
}
65
if (running) {
66
return System.currentTimeMillis() - startTime;
67
} else {
68
return stopTime - startTime;
69
}
70
}
71
}
72
73