-
Notifications
You must be signed in to change notification settings - Fork 317
/
XtendIncrementalBuilderPerformanceTest.java
187 lines (171 loc) · 5.55 KB
/
XtendIncrementalBuilderPerformanceTest.java
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtend.core.tests.building;
import com.google.common.base.Stopwatch;
import com.google.inject.Inject;
import com.google.inject.Injector;
import java.util.concurrent.TimeUnit;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtend.core.tests.RuntimeInjectorProvider;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.build.BuildRequest;
import org.eclipse.xtext.java.JavaSourceLanguageSetup;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Performance test for a code base mixed between Xtend and Java sources
*/
@InjectWith(XtendIncrementalBuilderPerformanceTest.InjectorProviderWithJavaSourceLang.class)
@RunWith(XtextRunner.class)
@SuppressWarnings("all")
public class XtendIncrementalBuilderPerformanceTest extends AbstractIncrementalBuilderTest {
public static class InjectorProviderWithJavaSourceLang extends RuntimeInjectorProvider {
@Override
protected Injector internalCreateInjector() {
new JavaSourceLanguageSetup().createInjectorAndDoEMFRegistration();
return super.internalCreateInjector();
}
}
@Inject
private IResourceServiceProvider.Registry registry;
@Override
protected IResourceServiceProvider.Registry getLanguages() {
return this.registry;
}
public void doTestPerformance(final int max) {
final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
final Function1<Integer, URI> _function_1 = (Integer it_1) -> {
return this.toFile((it_1).intValue(), max);
};
it.setDirtyFiles(IterableExtensions.<URI>toList(IterableExtensions.<Integer, URI>map(new IntegerRange(1, max), _function_1)));
};
final BuildRequest buildRequest = this.newBuildRequest(_function);
final Stopwatch sw = Stopwatch.createStarted();
this.build(buildRequest);
StringConcatenation _builder = new StringConcatenation();
_builder.append(max);
_builder.append(" file took ");
long _elapsed = sw.elapsed(TimeUnit.MILLISECONDS);
_builder.append(_elapsed);
_builder.append(" ms");
InputOutput.<String>println(_builder.toString());
}
public URI toFile(final int number, final int max) {
String _xifexpression = null;
if (((number % 2) == 0)) {
_xifexpression = ".xtend";
} else {
_xifexpression = ".java";
}
String _plus = (("demo/Demo" + Integer.valueOf(number)) + _xifexpression);
StringConcatenation _builder = new StringConcatenation();
_builder.append("package demo;");
_builder.newLine();
_builder.append("public class Demo");
_builder.append(number);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
if (((number % 2) == 0)) {
_builder.append("\t");
_builder.append("private String x");
_builder.newLine();
_builder.append("\t");
_builder.append(";");
_builder.newLine();
} else {
_builder.append("\t");
_builder.append("private String x");
_builder.newLine();
_builder.append("\t");
_builder.append(";");
_builder.newLine();
}
}
{
if ((number > 1)) {
_builder.append("\t");
_builder.append("private Demo");
_builder.append((number - 1), "\t");
_builder.append(" demoA;");
_builder.newLineIfNotEmpty();
}
}
{
if ((number > 2)) {
_builder.append("\t");
_builder.append("private Demo");
_builder.append((number - 2), "\t");
_builder.append(" demoB;");
_builder.newLineIfNotEmpty();
}
}
{
if ((number < (max - 1))) {
_builder.append("\t");
_builder.append("private Demo");
_builder.append((number + 1), "\t");
_builder.append(" demoC;");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
return this.operator_minus(_plus, _builder.toString());
}
@Test
public void testPerf00100() {
this.doTestPerformance(100);
}
@Test(timeout = 30000)
public void testPerf00200() {
this.doTestPerformance(200);
}
@Test(timeout = 30000)
public void testPerf00400() {
this.doTestPerformance(400);
}
@Test(timeout = 30000)
public void testPerf00800() {
this.doTestPerformance(800);
}
@Test(timeout = 30000)
public void testPerf01600() {
this.doTestPerformance(1600);
}
@Test(timeout = 30000)
public void testPerf03200() {
this.doTestPerformance(3200);
}
@Test(timeout = 30000)
public void testPerf06400() {
this.doTestPerformance(6400);
}
@Test(timeout = 60000)
public void testPerf12800() {
this.doTestPerformance(12800);
}
@Test(timeout = 120000)
public void testPerf25600() {
this.doTestPerformance(25600);
}
@Test(timeout = 240000)
public void testPerf51200() {
this.doTestPerformance(51200);
}
}