Permalink
Browse files

add benchmarks

  • Loading branch information...
namin committed Oct 4, 2017
1 parent fe840b9 commit 7cf2a2fc494a6f23f59316e12d2a3a8b80f31cf6
Showing with 53 additions and 0 deletions.
  1. +41 −0 popl18/bench.scala
  2. +11 −0 popl18/build.sbt
  3. +1 −0 popl18/test-main.scala
@@ -0,0 +1,41 @@
import org.scalameter._
import Base._
import Lisp._
import PinkBase._
import Pink._
object Bench {
def bench(thunk: => Unit) = {
val time = measure {
for (i <- 0 until 100000) {
thunk
}
}
time
}
def test() = {
println("fac #,evaluated,compiled,traced evaluated,traced compiled")
val oldLog = Base.log
try {
var counter = 0
Base.log = {x => counter += 1 }
val Code(fac_compiled) = ev(s"($evalc_src (quote $fac_src))")
val Code(fac_traced_compiled) = ev(s"($trace_n_evalc_src (quote $fac_src))")
val trace_n_eval_src = ev_nil(ev_nolift(evt_poly_src))
val trace_n_eval_val = parseExp(trace_n_eval_src)
val trace_n_eval_exp1 = trans(trace_n_eval_val, List("arg1"))
for (i <- 0 until 10) {
val t1 = bench(run { evalms(List(fac_val),App(App(eval_exp1,Var(0)),Lit(i))) })
val t2 = bench(run { evalms(Nil,App(fac_compiled,Lit(i))) })
val t3 = bench(run { evalms(List(fac_val),App(App(trace_n_eval_exp1,Var(0)),Lit(i))) })
val t4 = bench(run { evalms(Nil,App(fac_traced_compiled,Lit(i))) })
println(s"$i,$t1,$t2,$t3,$t4")
}
} finally {
Base.log = oldLog
}
}
}
@@ -2,3 +2,14 @@ scalaVersion := "2.12.3"
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
resolvers += "Sonatype OSS Snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies += "com.storm-enroute" %% "scalameter" % "0.8.2"
testFrameworks += new TestFramework(
"org.scalameter.ScalaMeterFramework")
logBuffered := false
parallelExecution in Test := false
@@ -4,5 +4,6 @@ object TestMain {
Pink_CPS.test()
Pink_clambda.test()
Matcher.test()
Bench.test()
}
}

0 comments on commit 7cf2a2f

Please sign in to comment.