Execute test 100x to warm up JVM
This commit is contained in:
parent
d6356ea788
commit
5baff562c7
@ -7,11 +7,11 @@ import eu.mikroskeem.shuriken.common.streams.ByteArrays;
|
|||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String... args){
|
public static void main(String... args){
|
||||||
System.out.println("==== Väikese class faili pakkimise test");
|
System.out.println("==== Väikese class faili pakkimise test (100x)");
|
||||||
byte[] classFile = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/Test.class"));
|
byte[] classFile = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/Test.class"));
|
||||||
Utils.generateReport(classFile);
|
Utils.generateReport(classFile);
|
||||||
|
|
||||||
System.out.println("=== Suure class faili pakkimise test");
|
System.out.println("=== Suure class faili pakkimise test (100x)");
|
||||||
byte[] classFile2 = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/TestBig.class"));
|
byte[] classFile2 = ByteArrays.fromInputStream(Main.class.getResourceAsStream("/TestBig.class"));
|
||||||
Utils.generateReport(classFile2);
|
Utils.generateReport(classFile2);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static eu.mikroskeem.uurimustoo.algoritmidetest.Utils.DummyCompressor.of;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Vainomaa
|
* @author Mark Vainomaa
|
||||||
*/
|
*/
|
||||||
@ -38,10 +40,14 @@ public class Utils {
|
|||||||
|
|
||||||
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor){
|
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor){
|
||||||
String compressorName = compressor.getName();
|
String compressorName = compressor.getName();
|
||||||
|
boolean decompressFailed = false;
|
||||||
|
|
||||||
|
/* Measure compressing speed */
|
||||||
Instant start = Instant.now();
|
Instant start = Instant.now();
|
||||||
byte[] compressed = compressor.compress(input);
|
byte[] compressed = compressor.compress(input);
|
||||||
Instant end = Instant.now();
|
Instant end = Instant.now();
|
||||||
/* Verify for sure */
|
|
||||||
|
/* Measure decompressing speed and validate it */
|
||||||
Instant start2 = null;
|
Instant start2 = null;
|
||||||
Instant end2 = null;
|
Instant end2 = null;
|
||||||
try {
|
try {
|
||||||
@ -52,22 +58,32 @@ public class Utils {
|
|||||||
assert decompressed.length == input.length;
|
assert decompressed.length == input.length;
|
||||||
} catch (Throwable e){
|
} catch (Throwable e){
|
||||||
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
||||||
compressorName = compressorName + " (katki)";
|
decompressFailed = true;
|
||||||
}
|
}
|
||||||
float diff = (float)input.length / (float)compressed.length;
|
float sizeDiff = (float)input.length / (float)compressed.length;
|
||||||
int compressTime = Duration.between(start, end).getNano();
|
int compressTime = Duration.between(start, end).getNano();
|
||||||
int decompressTime = start2!=null&&end2!=null?Duration.between(start2, end2).getNano():-1;
|
int decompressTime = start2!=null&&end2!=null?Duration.between(start2, end2).getNano():-1;
|
||||||
return new CompressorResult(compressorName, compressed.length, diff, compressTime, decompressTime);
|
return new CompressorResult(compressor, decompressFailed, compressed.length, sizeDiff, compressTime, decompressTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CompressorResult> executeAllAndSort(byte[] input){
|
public static List<CompressorResult> executeAllNTimes(byte[] input, int n){
|
||||||
List<CompressorResult> compressorResults = getAllCompressors().stream()
|
int i = 0;
|
||||||
.map(c -> executeCompressor(input, c))
|
List<CompressorResult> lastExecuted = executeAll(input, getAllCompressors());
|
||||||
.collect(Collectors.toList());
|
while(i < n-1){
|
||||||
compressorResults.add(new CompressorResult("Orginaal", input.length, 1, -1, -1)); // Inject original size
|
lastExecuted = executeAll(input, lastExecuted.stream()
|
||||||
Collections.sort(compressorResults);
|
.filter(r -> !r.isDecompressFailed())
|
||||||
Collections.reverse(compressorResults);
|
.map(CompressorResult::getCompressor)
|
||||||
return compressorResults;
|
.collect(Collectors.toList()));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
lastExecuted.add(of(input.length));
|
||||||
|
Collections.sort(lastExecuted);
|
||||||
|
Collections.reverse(lastExecuted);
|
||||||
|
return lastExecuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CompressorResult> executeAll(byte[] input, List<AbstractAlgorithm> compressors){
|
||||||
|
return compressors.stream().map(c -> executeCompressor(input, c)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateReport(byte[] input){
|
public static void generateReport(byte[] input){
|
||||||
@ -75,10 +91,10 @@ public class Utils {
|
|||||||
System.out.println("----------------------------------------------------------------------------");
|
System.out.println("----------------------------------------------------------------------------");
|
||||||
System.out.println("| Algoritm | Suurus | Väiksem | Aeg | Aeg (lahti) |");
|
System.out.println("| Algoritm | Suurus | Väiksem | Aeg | Aeg (lahti) |");
|
||||||
/* Show other results */
|
/* Show other results */
|
||||||
executeAllAndSort(input).forEach(compressorResult -> {
|
executeAllNTimes(input, 100).forEach(compressorResult -> {
|
||||||
System.out.println("|----------------|--------------|--------------|-------------|-------------|");
|
System.out.println("|----------------|--------------|--------------|-------------|-------------|");
|
||||||
System.out.format("| %-12s| %-10s| x%-10.3f| %-9s| %-9s|%n",
|
System.out.format("| %-12s| %-10s| x%-10.3f| %-9s| %-9s|%n",
|
||||||
compressorResult.getCompressorName(),
|
compressorResult.getCompressor().getName(),
|
||||||
compressorResult.getSize(),
|
compressorResult.getSize(),
|
||||||
compressorResult.getDifference(),
|
compressorResult.getDifference(),
|
||||||
(compressorResult.getTimeInNS() / 1000000)+"ms",
|
(compressorResult.getTimeInNS() / 1000000)+"ms",
|
||||||
@ -91,7 +107,8 @@ public class Utils {
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
public static class CompressorResult implements Comparable<CompressorResult> {
|
public static class CompressorResult implements Comparable<CompressorResult> {
|
||||||
private final String compressorName;
|
private final AbstractAlgorithm compressor;
|
||||||
|
private final boolean decompressFailed;
|
||||||
private final int size;
|
private final int size;
|
||||||
private final float difference;
|
private final float difference;
|
||||||
private final int timeInNS;
|
private final int timeInNS;
|
||||||
@ -102,4 +119,12 @@ public class Utils {
|
|||||||
return new Integer(size).compareTo(o.getSize());
|
return new Integer(size).compareTo(o.getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class DummyCompressor extends AbstractAlgorithm {
|
||||||
|
@Getter private final String name = "Orginaal";
|
||||||
|
|
||||||
|
static CompressorResult of(int size){
|
||||||
|
return new CompressorResult(new DummyCompressor(), false, size, 1.0F, -1, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user