Skip to content

Commit fdf6a23

Browse files
author
albertotn
committed
added execution time in csv file
1 parent a80911c commit fdf6a23

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

src/main/java/AllocationCsvExporter.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import java.util.Arrays;
99
import java.util.List;
1010
import java.util.LongSummaryStatistics;
11+
import java.util.stream.Collectors;
1112

1213
public class AllocationCsvExporter {
1314

1415
public static final AllocationCsvExporter INSTANCE = new AllocationCsvExporter();
1516

1617
private AllocationCsvExporter() {}
1718

18-
public void writeAllocationsToCsv(Maven3Version maven3Version, long[] allocations, String resultFilePath) throws IOException {
19+
public void writeAllocationsToCsv(Maven3Version maven3Version, AllocationTimePair[] allocations, String resultFilePath) throws IOException {
1920

2021
int numberOfAllocations = allocations.length;
2122
CSVFormat csvFormat = buildCsvFormat(resultFilePath, numberOfAllocations);
@@ -37,7 +38,7 @@ private CSVFormat buildCsvFormat(String resultFilePath, int numberOfAllocations)
3738
}
3839

3940
private String[] buildCsvHeaders(int numberOfAllocations) {
40-
String[] csvHeaders = new String[(2 * numberOfAllocations) + 5];
41+
String[] csvHeaders = new String[(3 * numberOfAllocations) +5];
4142
csvHeaders[0] = "Maven version";
4243
csvHeaders[1] = "Average (bytes)";
4344
csvHeaders[2] = "Average (Gb)";
@@ -47,32 +48,40 @@ private String[] buildCsvHeaders(int numberOfAllocations) {
4748
for (int i = 1; i < numberOfAllocations + 1; i++) {
4849
csvHeaders[i + 4] = "Allocation" + " " + i + " "+ "(bytes)";
4950
}
51+
52+
for (int i = 1; i < numberOfAllocations + 1; i++) {
53+
csvHeaders[i + 4+ numberOfAllocations] = "Lenght" + " " + i + " "+ "(seconds)";
54+
}
5055

5156
for (int i = 1; i < numberOfAllocations + 1; i++) {
52-
csvHeaders[i + 4 + numberOfAllocations] = "Allocation" + " " + i + " "+ "(Gb)";
57+
csvHeaders[i + 4 + numberOfAllocations*2] = "Allocation" + " " + i + " "+ "(Gb)";
5358
}
5459
return csvHeaders;
5560
}
5661

57-
private List<Object> buildCsvRecord(Maven3Version maven3Version, long[] allocations) {
62+
private List<Object> buildCsvRecord(Maven3Version maven3Version, AllocationTimePair[] input) {
5863

59-
List<Object> csvRecord = new ArrayList<>((2 * allocations.length) + 5);
64+
List<Object> csvRecord = new ArrayList<>((2 * input.length) + 5);
6065

6166
csvRecord.add(maven3Version);
6267

63-
LongSummaryStatistics allocationStatistics = Arrays.stream(allocations).summaryStatistics();
68+
LongSummaryStatistics allocationStatistics = Arrays.stream(input).collect(Collectors.summarizingLong(AllocationTimePair::getAllocationInBytes));
6469
double averageAllocationInBytes = allocationStatistics.getAverage();
6570
csvRecord.add(averageAllocationInBytes);
6671
csvRecord.add(averageAllocationInBytes / Math.pow(1024, 3));
6772
csvRecord.add(allocationStatistics.getMin());
6873
csvRecord.add(allocationStatistics.getMax());
6974

70-
for (int i = 0; i < allocations.length; i++) {
71-
csvRecord.add(allocations[i]);
75+
for (int i = 0; i < input.length; i++) {
76+
csvRecord.add(input[i].getAllocationInBytes());
7277
}
73-
74-
for (int i = 0; i < allocations.length; i++) {
75-
csvRecord.add(allocations[i] / Math.pow(1024, 3));
78+
79+
for (int i = 0; i < input.length; i++) {
80+
csvRecord.add(input[i].getLenghtInSeconds());
81+
}
82+
83+
for (int i = 0; i < input.length; i++) {
84+
csvRecord.add(input[i].getAllocationInBytes() / Math.pow(1024, 3));
7685
}
7786

7887
return csvRecord;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
public class AllocationTimePair {
3+
4+
private final Long allocationInBytes;
5+
private final Long lenghtInSeconds;
6+
7+
public AllocationTimePair(Long allocationInBytes, Long lenghtInSeconds) {
8+
this.allocationInBytes = allocationInBytes;
9+
this.lenghtInSeconds = lenghtInSeconds;
10+
}
11+
12+
public Long getAllocationInBytes() {
13+
return allocationInBytes;
14+
}
15+
16+
public Long getLenghtInSeconds() {
17+
return lenghtInSeconds;
18+
}
19+
20+
21+
}

src/test/java/MvnValidateAllocationByMaven3VersionTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void measure() throws IOException {
9090

9191
applyWarmMeasurements(maven3Version, testClass);
9292

93-
long[] allocations = measureAllocationSeveralTimes(testClass, numberOfMeasuresByVersion);
93+
AllocationTimePair[] allocations = measureAllocationSeveralTimes(testClass, numberOfMeasuresByVersion);
9494

9595
AllocationCsvExporter.INSTANCE.writeAllocationsToCsv(maven3Version
9696
, allocations
@@ -134,25 +134,28 @@ private String getDateTimeAsString() {
134134
return df.format(new Date());
135135
}
136136

137-
private long[] measureAllocationSeveralTimes(Class<?> testClass, int numberOfTimes) throws IOException {
138-
long[] allocations = new long[numberOfTimes];
137+
private AllocationTimePair[] measureAllocationSeveralTimes(Class<?> testClass, int numberOfTimes) throws IOException {
138+
AllocationTimePair[] allocations = new AllocationTimePair[numberOfTimes];
139139
for (int i = 0; i < numberOfTimes; i++) {
140-
long allocationInBytes = measureAllocation(testClass);
141-
allocations[i] = allocationInBytes;
140+
allocations[i] =measureAllocation(testClass);
142141
}
143142
return allocations;
144143
}
145144

146-
private Long measureAllocation(Class<?> testClass) throws IOException {
145+
private AllocationTimePair measureAllocation(Class<?> testClass) throws IOException {
147146
deleteQuickPerfFoldersInTemp();
147+
long startTime = System.currentTimeMillis();
148148
PrintableResult printableResult = testResult(testClass);
149+
long executionTimeInMilliseconds = System.currentTimeMillis() - startTime;
149150
if(printableResult.failureCount() != 0) {
150151
System.out.println("Allocation can't be measured. " + printableResult.toString());
151152
}
152153
Long allocationInBytes = retrieveMeasuredAllocationInBytes();
154+
Long lenghtInSeconds = executionTimeInMilliseconds/1000l;
153155
System.out.println("Allocation in bytes: " + allocationInBytes);
156+
System.out.println("Lenght in seconds: " + lenghtInSeconds);
154157
System.out.println("----------------");
155-
return allocationInBytes;
158+
return new AllocationTimePair(allocationInBytes, lenghtInSeconds);
156159
}
157160

158161
private void deleteQuickPerfFoldersInTemp() throws IOException {

0 commit comments

Comments
 (0)