long start = System.nanoTime();
byte[] bytes = writer.write(object);
long writeTime = System.nanoTime() - start;
start = System.nanoTime();
Document result = reader.read(new ByteArrayInputStream(bytes));
long readTime = System.nanoTime() - start;
if (compareToOtherImpls) {
// Convert to MongoDB, write to bytes, and compare ...
BSONObject mongoData = createMongoData(object);
start = System.nanoTime();
byte[] mongoBytes = new BasicBSONEncoder().encode(mongoData);
long mongoWriteTime = System.nanoTime() - start;
assertSame(bytes, mongoBytes, "BSON ", "Mongo ");
// FYI: The Jackson BSON library writes several of the types incorrectly,
// whereas the MongoDB library seems to write things per the spec.
// // Convert to Jackson BSON, write to bytes, and compare ...
// ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
// ObjectMapper om = new ObjectMapper(new BsonFactory());
// Map<String, Object> jacksonData = createJacksonData(object);
// om.writeValue(stream2, jacksonData);
// byte[] jacksonBytes = stream2.toByteArray();
// assertSame(bytes, jacksonBytes, "BSON ", "Jackson");
start = System.nanoTime();
new BasicBSONDecoder().decode(bytes, new BasicBSONCallback());
long mongoReadTime = System.nanoTime() - start;
Document fromMongo = reader.read(new ByteArrayInputStream(mongoBytes));
if (!fromMongo.equals(result)) {
System.out.println("from Schematic: " + result);
System.out.println("from Mongo: " + fromMongo);
assert false : "Document read from bytes written by Mongo did not match expected document: " + result;
}