Skip to content

Instantly share code, notes, and snippets.

@andrewconner
Created February 11, 2013 21:56
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 andrewconner/4757963 to your computer and use it in GitHub Desktop.
Save andrewconner/4757963 to your computer and use it in GitHub Desktop.
def timer(f: => Any): Long = {
val startTime = System.nanoTime
val ret = f
val endTime = System.nanoTime
endTime - startTime
}
def iterTest(f: => Any): Double = {
(for(i <- 0 to 10000) yield timer(f)).sorted.apply(5000)
}
val d_norm = iterTest {
running(FakeApplication()) {
val translated = route(FakeRequest(GET, "/greet/Barney")).get
contentAsString(translated) must contain ("Barney")
}
}
println(s"Normal Play! way:\t$d_norm")
val inj_avg = iterTest {
running(FakeApplication(withGlobal = Some(FakeTranslatorGlobal))) {
val home = route(FakeRequest(GET, "/greet/Barney")).get
contentAsString(home) must contain ("Hello Barney")
}
}
println(s"Injected:\t\t$inj_avg")
val d_avg = iterTest {
val controller = new Translate(new FakeTranslator)
val result = controller.greet(name = "Barney")(FakeRequest())
contentAsString(result) must contain ("Hello Barney")
}
println(s"Direct:\t\t\t$d_avg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment