forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsingTest.java
More file actions
49 lines (46 loc) · 1.59 KB
/
Copy pathParsingTest.java
File metadata and controls
49 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
package net.sdo;
public class ParsingTest {
public static void main(String[] args) throws Exception {
int nIterations = 1000000;
int nWarmupIterations = 1000000;
int curArg = 0;
while (args[curArg].startsWith("-")) {
if (args[curArg].equals("-n")) {
nIterations = Integer.parseInt(args[++curArg]);
}
else if (args[curArg].equals("-w")) {
nWarmupIterations = Integer.parseInt(args[++curArg]);
}
else {
usage();
}
curArg++;
}
RunParams rp = new RunParams(args[curArg]);
AbstractParsingTest pti = (AbstractParsingTest) Class.forName(rp.getClassName()).newInstance();
pti.init(rp);
for (int i = 0; i < nWarmupIterations; i++) {
pti.run();
}
System.gc();
System.runFinalization();
System.gc();
System.out.println("Starting Measurement");
long then = System.currentTimeMillis();
for (int i = 0; i < nIterations; i++) {
pti.run();
}
long now = System.currentTimeMillis();
long elapsed = now - then;
System.out.println("Time to execute " + nIterations + " iterations is " + elapsed);
System.out.println("Time per operation: " + ((double) elapsed) / nIterations);
}
private static void usage() {
System.out.println("Usage:");
System.out.println("java ParsingTest TestClassName");
System.exit(-1);
}
}