Skip to content

Commit

Permalink
Add benchmark utility that helps address scala#422
Browse files Browse the repository at this point in the history
* Add just a memo that will tell us how many times we are looking for
the pickler/unpickler of a type `T`.
  • Loading branch information
jvican committed May 24, 2016
1 parent 12d578c commit 4098b7c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/scala/scala/pickling/generator/PicklingMacros.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scala.pickling
package generator

import scala.collection.mutable

private[pickling] trait PicklingMacros extends Macro with SourceGenerator with TypeAnalysis {

implicit val implContext = c
Expand Down Expand Up @@ -49,6 +51,7 @@ private[pickling] trait PicklingMacros extends Macro with SourceGenerator with T
}
}


def preferExistingImplicits(body: => Tree): Tree = {

import Compat._
Expand All @@ -58,11 +61,15 @@ private[pickling] trait PicklingMacros extends Macro with SourceGenerator with T
if (candidates.isEmpty) return body
val ourPt = candidates.head.pt

val key = ourPt.toString
Memo.memo += key -> (Memo.memo.getOrElse(key, 0) + 1)

def debug(msg: Any) = {
val padding = " " * (candidates.length - 1)
Console.err.println(padding + msg)
}

debug(YELLOW_B + s"We have entered here ${Memo.memo.get(key)}" + RESET)
debug(MAGENTA_B + "Can we enter " + ourPt + "?" + RESET)
debug(candidates)

Expand Down Expand Up @@ -102,3 +109,7 @@ private[pickling] trait PicklingMacros extends Macro with SourceGenerator with T
}

}

object Memo {
val memo = mutable.Map.empty[String, Int]
}

0 comments on commit 4098b7c

Please sign in to comment.