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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.performance;
import java.io.File;
import java.io.PrintStream;
import junit.framework.Test;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
/**
*/
@SuppressWarnings("rawtypes")
public class FullSourceWorkspaceFormatterTests extends FullSourceWorkspaceTests {
// Tests counters
static int TESTS_COUNT = 0;
private final static int WARMUP_COUNT = 5;
static int TESTS_LENGTH;
// Log file streams
private static PrintStream[] LOG_STREAMS = new PrintStream[DIM_NAMES.length];
// Type path
static IPath FORMAT_TYPE_PATH;
static String FORMAT_TYPE_SOURCE;
/**
* @param name
*/
public FullSourceWorkspaceFormatterTests(String name) {
super(name);
}
static {
// TESTS_NAMES = new String[] {
// };
}
public static Test suite() {
Test suite = buildSuite(testClass());
TESTS_LENGTH = TESTS_COUNT = suite.countTestCases();
createPrintStream(testClass(), LOG_STREAMS, TESTS_COUNT, null);
return suite;
}
private static Class testClass() {
return FullSourceWorkspaceFormatterTests.class;
}
protected void setUp() throws Exception {
super.setUp();
// Read big file
System.out.print(" - Read big file source...");
long start = System.currentTimeMillis();
FORMAT_TYPE_SOURCE = Util.fileContent(getPluginBinariesDirectoryPath()+File.separator+"GenericTypeTest.java");
System.out.println("("+(System.currentTimeMillis()-start)+"ms)");
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
// End of execution => one test less
TESTS_COUNT--;
// Log perf result
if (LOG_DIR != null) {
logPerfResult(LOG_STREAMS, TESTS_COUNT);
}
// Print statistics
if (TESTS_COUNT == 0) {
// System.out.println("-------------------------------------");
// System.out.println("Format performance test statistics:");
// NumberFormat intFormat = NumberFormat.getIntegerInstance();
// System.out.println("-------------------------------------\n");
}
super.tearDown();
}
/**
* Format file (Parser.java - 225176 chars) using code formatter default options.
*/
public void testFormatDefault() throws JavaModelException {
tagAsSummary("Format file with default options", false); // do NOT put in fingerprint
// Warm up
String source = PARSER_WORKING_COPY.getSource();
int warmup = WARMUP_COUNT;
for (int i=0; i<warmup; i++) {
long start = System.currentTimeMillis();
new DefaultCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, null);
if (i==0) {
System.out.println(" Time to format file ("+source.length()+" chars) = "+(System.currentTimeMillis()-start)+"ms");
}
}
// Measures
resetCounters();
int measures = MEASURES_COUNT;
for (int i=0; i<measures; i++) {
runGc();
startMeasuring();
for (int j=1; j<10; j++)
new DefaultCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, null);
stopMeasuring();
}
// Commit
commitMeasurements();
assertPerformance();
}
/**
* Format big file (GenericTypeTest.java - 1297242 chars) using code formatter default options.
*/
public void testFormatDefaultBigFile() {
tagAsSummary("Format big file with default options", false); // do NOT put in fingerprint yet...
// Warm up
String source = FORMAT_TYPE_SOURCE;
int warmup = WARMUP_COUNT;
for (int i=0; i<warmup; i++) {
long start = System.currentTimeMillis();
new DefaultCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, null);
if (i==0) {
System.out.println(" Time to format big file ("+source.length()+" chars) = "+(System.currentTimeMillis()-start)+"ms");
}
}
// Measures
resetCounters();
int measures = MEASURES_COUNT;
for (int i=0; i<measures; i++) {
runGc();
startMeasuring();
new DefaultCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, null);
stopMeasuring();
}
// Commit
commitMeasurements();
assertPerformance();
}
protected void resetCounters() {
// do nothing
}
}
|