System.out.println(name + ":");
// compress it
List<Long> compressDurations = new ArrayList<Long>();
ByteArrayOutputStream compressedStream = new ByteArrayOutputStream();
CompressionOutputStream compressingStream =
algorithm.createPlainCompressionStream(compressedStream, compressor);
try {
for (int itTime = 0; itTime < benchmarkNTimes; ++itTime) {
final long startTime = System.nanoTime();
compressingStream.resetState();
compressedStream.reset();
compressingStream.write(buffer, offset, length);
compressingStream.flush();
compressedStream.toByteArray();
final long finishTime = System.nanoTime();
// add time record
if (itTime >= benchmarkNOmit) {
compressDurations.add(finishTime - startTime);
}
}
} catch (IOException e) {
throw new RuntimeException(String.format(
"Benchmark, or encoding algorithm '%s' cause some stream problems",
name), e);
}
compressingStream.close();
printBenchmarkResult(length, compressDurations, Manipulation.COMPRESSION);
byte[] compBuffer = compressedStream.toByteArray();
// uncompress it several times and measure performance