Revisions
-
teamon created this gist
Mar 8, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import Benchmark._ object App { def main(args: Array[String]): Unit = { benchmark(100000){ report("foo"){ foo() } :: report("bar"){ bar() } :: Nil } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ object Benchmark { case class BenchmarkReport(name: String, f: () => Unit){ def run(n: Int) = { val start = System.currentTimeMillis (1 to n) foreach { i => f() } val time = System.currentTimeMillis - start (name, time) } } def benchmark(n: Int)(reports: List[BenchmarkReport]) = { val results = reports.map(_.run(n)) println("Name Time(s)") println("===============================") results.foreach { case (name, time) => printf("%-20s %10f\n", name, time / 1000.0) } results } def report(name: String)(f: => Unit) = BenchmarkReport(name, f _) } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ Name Time(s) =============================== foo 0.084000 bar 0.082000