Created
February 3, 2012 20:49
-
-
Save bwmcadams/1732431 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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