Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

pretty profile function #10

Merged
merged 1 commit into from

2 participants

Gregg Carrier Tony Tam
Gregg Carrier

should be able to go:

profile("myFuntionName") {
//codez
}

Tony Tam fehguy merged commit 344a70e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2012
  1. made a pretty profile function

    Gregg authored
This page is out of date. Refresh to see the latest.
22 modules/common-utils/src/main/scala/com/wordnik/util/perf/Profile.scala
View
@@ -19,24 +19,26 @@ object Profile {
counterList.sortWith(_.key > _.key).toList
}
- def apply[T](name: String, f: => T, output: Boolean): T = {
+ def apply[T](name: String, f: => T, output: Boolean = false): T = {
+ doProfile(name, f, output)
+ }
+
+ def profile[T](name: String, output: Boolean = false)(f: => T): T = {
+ doProfile(name, f, output)
+ }
+
+ private def doProfile[T](name:String, f: => T, output: Boolean):T = {
val p = Profile(name)
try f
finally {
p.finish
output match {
- case true => println(name, p.getDuration)
- case _ =>
+ case true => println(name, p.getDuration)
+ case _ =>
}
}
}
- def apply[T](name: String, f: => T): T = {
- val p = Profile(name)
- try f
- finally p.finish
- }
-
def processTriggers(counter: ProfileCounter) = {
triggers.foreach(t => t.apply(counter))
}
@@ -129,4 +131,4 @@ case class Profile(key: String) {
case _ => end - start
}
}
-}
+}
Something went wrong with that request. Please try again.