More detailed report (time, how much smaller etc.)
This commit is contained in:
parent
590f5f7d11
commit
d6356ea788
@ -8,6 +8,8 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -36,24 +38,33 @@ public class Utils {
|
||||
|
||||
public static CompressorResult executeCompressor(byte[] input, AbstractAlgorithm compressor){
|
||||
String compressorName = compressor.getName();
|
||||
Instant start = Instant.now();
|
||||
byte[] compressed = compressor.compress(input);
|
||||
Instant end = Instant.now();
|
||||
/* Verify for sure */
|
||||
Instant start2 = null;
|
||||
Instant end2 = null;
|
||||
try {
|
||||
start2 = Instant.now();
|
||||
byte[] decompressed = compressor.decompress(compressed);
|
||||
end2 = Instant.now();
|
||||
Validate.checkGeneratedClass(decompressed);
|
||||
assert decompressed.length == input.length;
|
||||
} catch (Throwable e){
|
||||
System.out.println(String.format("Tekkis viga %s algoritmi lahtipakkimisel! %s", compressorName, e.toString()));
|
||||
compressorName = compressorName + " (katki)";
|
||||
}
|
||||
return new CompressorResult(compressorName, compressed.length);
|
||||
float diff = (float)input.length / (float)compressed.length;
|
||||
int compressTime = Duration.between(start, end).getNano();
|
||||
int decompressTime = start2!=null&&end2!=null?Duration.between(start2, end2).getNano():-1;
|
||||
return new CompressorResult(compressorName, compressed.length, diff, compressTime, decompressTime);
|
||||
}
|
||||
|
||||
public static List<CompressorResult> executeAllAndSort(byte[] input){
|
||||
List<CompressorResult> compressorResults = getAllCompressors().stream()
|
||||
.map(c -> executeCompressor(input, c))
|
||||
.collect(Collectors.toList());
|
||||
compressorResults.add(new CompressorResult("Orginaal", input.length)); // Inject original size
|
||||
compressorResults.add(new CompressorResult("Orginaal", input.length, 1, -1, -1)); // Inject original size
|
||||
Collections.sort(compressorResults);
|
||||
Collections.reverse(compressorResults);
|
||||
return compressorResults;
|
||||
@ -61,17 +72,20 @@ public class Utils {
|
||||
|
||||
public static void generateReport(byte[] input){
|
||||
|
||||
System.out.println("---------------------------------");
|
||||
System.out.println("| Algoritm | Suurus |");
|
||||
System.out.println("----------------------------------------------------------------------------");
|
||||
System.out.println("| Algoritm | Suurus | Väiksem | Aeg | Aeg (lahti) |");
|
||||
/* Show other results */
|
||||
executeAllAndSort(input).forEach(compressorResult -> {
|
||||
System.out.println("|----------------|--------------|");
|
||||
System.out.format("| %-12s| %-10s|%n",
|
||||
System.out.println("|----------------|--------------|--------------|-------------|-------------|");
|
||||
System.out.format("| %-12s| %-10s| x%-10.3f| %-9s| %-9s|%n",
|
||||
compressorResult.getCompressorName(),
|
||||
compressorResult.getSize()
|
||||
compressorResult.getSize(),
|
||||
compressorResult.getDifference(),
|
||||
(compressorResult.getTimeInNS() / 1000000)+"ms",
|
||||
(compressorResult.getDecompressTimeInNS() / 1000000)+"ms"
|
||||
);
|
||||
});
|
||||
System.out.println("|-------------------------------|");
|
||||
System.out.println("|--------------------------------------------------------------------------|");
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ -79,6 +93,9 @@ public class Utils {
|
||||
public static class CompressorResult implements Comparable<CompressorResult> {
|
||||
private final String compressorName;
|
||||
private final int size;
|
||||
private final float difference;
|
||||
private final int timeInNS;
|
||||
private final int decompressTimeInNS;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Utils.CompressorResult o) {
|
||||
|
Loading…
Reference in New Issue
Block a user