Skip to content

Instantly share code, notes, and snippets.

@bwmcadams
Created February 3, 2012 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwmcadams/1732431 to your computer and use it in GitHub Desktop.
Save bwmcadams/1732431 to your computer and use it in GitHub Desktop.
val encoder = new com.mongodb.DefaultDBEncoder()
def encode(doc: DBObject): Long = {
encoder.synchronized {
val start = System.currentTimeMillis()
val encoded = encoder.encode(doc)
val end = System.currentTimeMillis()
end - start
}
}
DeregisterConversionHelpers()
DeregisterJodaTimeConversionHelpers()
"Produce viable performance numbers to test off of " >> {
"Encoding DateTimes without any custom encoders registered " in {
var total = 0.0
val x = 1000000
for (n <- 1 to x) {
val doc = MongoDBObject("date" -> new JDKDate, "foo" -> "bar", "x" -> 5.2)
total += encode(doc)
}
val avg = total / x
log.error("[Basic] Average encoding time over %s tries: %f [%s]", x, avg, total)
avg must beGreaterThan(0.0)
}
"Encoding Joda DateTimes with custom encoders registered " in {
RegisterJodaTimeConversionHelpers()
var total = 0.0
val x = 1000000
for (n <- 1 to x) {
val doc = MongoDBObject("date" -> DateTime.now, "foo" -> "bar", "x" -> 5.2)
total += encode(doc)
}
val avg = total / x
log.error("[Custom Types] Average encoding time over %s tries: %f [%s]", x, avg, total)
avg must beGreaterThan(0.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment