Skip to content

Commit

Permalink
Merge pull request #103 from mawHBT/develop
Browse files Browse the repository at this point in the history
Started with "Fix Unit of Measurement Values" (issue #84)
  • Loading branch information
DaGeRe authored Feb 24, 2022
2 parents e19673a + 69c4b40 commit c2eb31e
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 29 deletions.
11 changes: 10 additions & 1 deletion src/main/java/de/dagere/peass/ci/MeasureVersionAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.dagere.peass.analysis.measurement.ProjectStatistics;
import de.dagere.peass.ci.helper.HistogramValues;
import de.dagere.peass.ci.helper.RCAVisualizer;
import de.dagere.peass.ci.helper.UnitConverter;
import de.dagere.peass.config.MeasurementConfig;
import de.dagere.peass.dependency.analysis.data.TestCase;
import de.dagere.peass.measurement.statistics.StatisticUtil;
Expand Down Expand Up @@ -126,6 +127,14 @@ public String getReducedName(final String name) {
}

public double round(final double value) {
return Math.round(value * 100) / 100d;
return Math.round(value * 10000) / 10000d;
}

public int getFactorByMean(final double mean) {
return UnitConverter.getFactorByMean(mean);
}

public String getUnitByFactor(final int factor) {
return UnitConverter.getUnitByFactor(factor);
}
}
57 changes: 57 additions & 0 deletions src/main/java/de/dagere/peass/ci/helper/UnitConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.dagere.peass.ci.helper;

public class UnitConverter {

public static final int NANOSECONDS_TO_MICROSECONDS = 1000;
public static final int NANOSECONDS_TO_MILLISECONDS = 1000 * 1000;
public static final int NANOSECONDS_TO_SECONDS = 1000 * 1000 * 1000;

public static final String NANOSECONDS = "ns";
public static final String MICROSECONDS = "\u00B5s";
public static final String MILLISECONDS = "ms";
public static final String SECONDS = "s";

public static int getFactorByMean(double mean) {
int count = 0;

while (count < 3 && mean >= 1000) {
mean = mean / 1000;
count++;
}

return getFactorByCount(count);
}

private static int getFactorByCount(final int count) {
switch (count) {
case 0:
return 1;
case 1:
return NANOSECONDS_TO_MICROSECONDS;
case 2:
return NANOSECONDS_TO_MILLISECONDS;
case 3:
return NANOSECONDS_TO_SECONDS;
default:
// this should not happen!
return 0;
}
}

public static String getUnitByFactor(final int factor) {
switch (factor) {
case 1:
return "ns";
case NANOSECONDS_TO_MICROSECONDS:
return "\u00B5s";
case NANOSECONDS_TO_MILLISECONDS:
return "ms";
case NANOSECONDS_TO_SECONDS:
return "s";
default:
// this should not happen!
return "unknown factor provided!";
}
}

}
25 changes: 25 additions & 0 deletions src/main/java/de/dagere/peass/ci/helper/ValuesAndUnit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.dagere.peass.ci.helper;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class ValuesAndUnit {

private final double[] values;
private final String unit;

@SuppressFBWarnings
public ValuesAndUnit(final double[] values, final String unit) {
this.values = values;
this.unit = unit;
}

@SuppressFBWarnings
public double[] getValues() {
return values;
}

public String getUnit() {
return unit;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<j:if test="${it.getUpdatedConfigurations().get(testcase.getKey()) == null}">
<j:set var="currentRepetitions" value="${it.config.repetitions}" />
</j:if>
<j:set var="factorOld" value="${it.getFactorByMean(currentStatistic.getMeanOld())}" />
<j:set var="unit" value="${it.getUnitByFactor(factorOld)}" />
<tr>
<th></th>
<th colspan="2">
Expand All @@ -52,56 +54,36 @@
<tr>
<td>${%mean}<br />${%measured}</td>
<td>
<j:if test="${currentStatistic.getMeanOld() &gt; 1000}">
${it.round(currentStatistic.getMeanOld()/1000)} $&#x00B5;s
</j:if>
<j:if test="${currentStatistic.getMeanOld() &lt; 1000}">
${it.round(currentStatistic.getMeanOld())} ns
</j:if>
${it.round(currentStatistic.getMeanOld() / factorOld)} ${unit}
</td>
<td>
<j:if test="${currentStatistic.getMeanOld() &gt; 1000}">
${it.round(currentStatistic.getMeanCurrent()/1000)} $&#x00B5;s
</j:if>
<j:if test="${currentStatistic.getMeanOld() &lt; 1000}">
${it.round(currentStatistic.getMeanCurrent())} ns
</j:if>
${it.round(currentStatistic.getMeanCurrent() / factorOld)} ${unit}
</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.getMeanOld()*currentRepetitions)} $&#x00B5;s</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.getMeanCurrent()*currentRepetitions)} $&#x00B5;s</td>
</tr>
<tr>
<td>${%standardDeviation}<br />${%measured}</td>
<td>
<j:if test="${currentStatistic.getMeanOld() &gt; 1000}">
${it.round(currentStatistic.deviationOld/1000)}
</j:if>
<j:if test="${currentStatistic.getMeanOld() &lt; 1000}">
${it.round(currentStatistic.deviationOld)}
</j:if>
${it.round(currentStatistic.deviationOld / factorOld)}
</td>
<td>
<j:if test="${currentStatistic.getMeanOld() &gt; 1000}">
${it.round(currentStatistic.deviationCurrent/1000)}
</j:if>
<j:if test="${currentStatistic.getMeanOld() &lt; 1000}">
${it.round(currentStatistic.deviationCurrent)}
</j:if>
${it.round(currentStatistic.deviationCurrent / factorOld)}
</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.deviationOld*currentRepetitions)}</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.deviationCurrent*currentRepetitions)}</td>
</tr>
<tr>
<td>${%mean}<br />${%perRepetition}</td>
<td> ${it.round(currentStatistic.getMeanOld()/currentRepetitions/1000)} $&#x00B5;s</td>
<td>${it.round(currentStatistic.getMeanCurrent()/currentRepetitions/1000)} $&#x00B5;s</td>
<td>${it.round(currentStatistic.getMeanOld() / currentRepetitions / factorOld)} ${unit}</td>
<td>${it.round(currentStatistic.getMeanCurrent() / currentRepetitions / factorOld)} ${unit}</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.getMeanOld())} $&#x00B5;s</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.getMeanCurrent())} $&#x00B5;s</td>
</tr>
<tr>
<td>${%standardDeviation}<br />${%perRepetition}</td>
<td>${it.round(currentStatistic.deviationOld/currentRepetitions/1000)}</td>
<td>${it.round(currentStatistic.deviationCurrent/currentRepetitions/1000)}</td>
<td>${it.round(currentStatistic.deviationOld / currentRepetitions / factorOld)}</td>
<td>${it.round(currentStatistic.deviationCurrent / currentRepetitions / factorOld)}</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.deviationOld)}</td>
<td class="fullMeasurement" style="display: none">${it.round(noWarmupStatistic.deviationCurrent)}</td>
</tr>
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/de/peass/ci/helper/TestUnitConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.peass.ci.helper;

import de.dagere.peass.ci.helper.UnitConverter;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

public class TestUnitConverter {

final double nanoSecondMean = 123;
final double mikroSecondMean = 1234;
final double milliSecondMean = 1234567;
final double secondMean = 12345678E6;

@Test
public void testGetFactorByMean() {
Assert.assertEquals(1, UnitConverter.getFactorByMean(nanoSecondMean));
Assert.assertEquals(UnitConverter.NANOSECONDS_TO_MICROSECONDS, UnitConverter.getFactorByMean(mikroSecondMean));
Assert.assertEquals(UnitConverter.NANOSECONDS_TO_MILLISECONDS, UnitConverter.getFactorByMean(milliSecondMean));
Assert.assertEquals(UnitConverter.NANOSECONDS_TO_SECONDS, UnitConverter.getFactorByMean(secondMean));
}

@Test
public void testGetUnitByFactor() {
Assert.assertEquals(UnitConverter.NANOSECONDS, UnitConverter.getUnitByFactor(1));
Assert.assertEquals(UnitConverter.MICROSECONDS, UnitConverter.getUnitByFactor(UnitConverter.NANOSECONDS_TO_MICROSECONDS));
Assert.assertEquals(UnitConverter.MILLISECONDS, UnitConverter.getUnitByFactor(UnitConverter.NANOSECONDS_TO_MILLISECONDS));
Assert.assertEquals(UnitConverter.SECONDS, UnitConverter.getUnitByFactor(UnitConverter.NANOSECONDS_TO_SECONDS));
}

}

0 comments on commit c2eb31e

Please sign in to comment.