public static void main(String[] args) throws IOException { // How many Cells to encode/decode on each cycle. final int count = 100000; // How many times to do an operation; repeat gives hotspot chance to warm up. final int cycles = 30; Cell [] cells = getCells(count); int size = getRoughSize(cells); int initialBufferSize = 2 * size; // Multiply by 2 to ensure we don't have to grow buffer // Test KeyValue codec. doCodec(new KeyValueCodec(), cells, cycles, count, initialBufferSize); doCodec(new CellCodec(), cells, cycles, count, initialBufferSize); doCodec(new MessageCodec(), cells, cycles, count, initialBufferSize); } }
static void doCodec(final Codec codec, final Cell [] cells, final int cycles, final int count, final int initialBufferSize) throws IOException { byte [] bytes = null; Cell [] cellsDecoded = null; for (int i = 0; i < cycles; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(initialBufferSize); Codec.Encoder encoder = codec.getEncoder(baos); bytes = runEncoderTest(i, initialBufferSize, baos, encoder, cells); } for (int i = 0; i < cycles; i++) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Codec.Decoder decoder = codec.getDecoder(bais); cellsDecoded = CodecPerformance.runDecoderTest(i, count, decoder); } verifyCells(cells, cellsDecoded); }
public static void main(String[] args) throws IOException { // How many Cells to encode/decode on each cycle. final int count = 100000; // How many times to do an operation; repeat gives hotspot chance to warm up. final int cycles = 30; Cell [] cells = getCells(count); int size = getRoughSize(cells); int initialBufferSize = 2 * size; // Multiply by 2 to ensure we don't have to grow buffer // Test KeyValue codec. doCodec(new KeyValueCodec(), cells, cycles, count, initialBufferSize); doCodec(new CellCodec(), cells, cycles, count, initialBufferSize); doCodec(new MessageCodec(), cells, cycles, count, initialBufferSize); } }
static void doCodec(final Codec codec, final Cell [] cells, final int cycles, final int count, final int initialBufferSize) throws IOException { byte [] bytes = null; Cell [] cellsDecoded = null; for (int i = 0; i < cycles; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(initialBufferSize); Codec.Encoder encoder = codec.getEncoder(baos); bytes = runEncoderTest(i, initialBufferSize, baos, encoder, cells); } for (int i = 0; i < cycles; i++) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Codec.Decoder decoder = codec.getDecoder(bais); cellsDecoded = CodecPerformance.runDecoderTest(i, count, decoder); } verifyCells(cells, cellsDecoded); }