Vertex<LongWritable, FloatWritable, DoubleWritable, LongWritable> vertex =
buildVertex(edgesClass);
long serializeNanosStart;
long serializeNanos = 0;
UnsafeByteArrayOutputStream outputStream = null;
for (int i = 0; i <
REPS; ++i) {
serializeNanosStart = SystemTime.get().getNanoseconds();
outputStream =
new UnsafeByteArrayOutputStream(32);
WritableUtils.writeVertexToDataOutput(outputStream, vertex, vertex.getConf());
serializeNanos += Times.getNanosecondsSince(SystemTime.get(),
serializeNanosStart);
}
serializeNanos /= REPS;
System.out.println("testUnsafeSerializeOutEdgesClass: " +
"Serializing took " +
serializeNanos +
" ns for " + outputStream.getPos()
+ " bytes " +
(outputStream.getPos() * 1f *
Time.NS_PER_SECOND / serializeNanos) +
" bytes / sec for " + edgesClass.getName());
Vertex<LongWritable, FloatWritable, DoubleWritable, LongWritable>
readVertex = buildVertex(edgesClass);
long deserializeNanosStart;
long deserializeNanos = 0;
for (int i = 0; i < REPS; ++i) {
deserializeNanosStart = SystemTime.get().getNanoseconds();
UnsafeByteArrayInputStream inputStream = new
UnsafeByteArrayInputStream(
outputStream.getByteArray(), 0, outputStream.getPos());
WritableUtils.reinitializeVertexFromDataInput(
inputStream, readVertex, readVertex.getConf());
deserializeNanos += Times.getNanosecondsSince(SystemTime.get(),
deserializeNanosStart);
}
deserializeNanos /= REPS;
System.out.println("testUnsafeSerializeOutEdgesClass: " +
"Deserializing took " +
deserializeNanos +
" ns for " + outputStream.getPos() +
" bytes " +
(outputStream.getPos() * 1f *
Time.NS_PER_SECOND / deserializeNanos) +
" bytes / sec for " + edgesClass.getName());
assertEquals(vertex.getId(), readVertex.getId());
assertEquals(vertex.getValue(), readVertex.getValue());