Skip to content

Instantly share code, notes, and snippets.

@hsienchiaolee
hsienchiaolee / ScalaBenchmark.scala
Created February 12, 2018 21:06
Helper function for simple method benchmarking
// Source: https://stackoverflow.com/questions/9160001/how-to-profile-methods-in-scala
def benchmark[R](runs: Int, block: => R) = {
def print_result(s: String, ns: Long) = {
val formatter = java.text.NumberFormat.getIntegerInstance
println("%-16s".format(s) + formatter.format(ns) + " ns")
}
var t0 = System.nanoTime()
var result = block // call-by-name
var t1 = System.nanoTime()

Keybase proof

I hereby claim:

  • I am hsienchiaolee on github.
  • I am kaidante (https://keybase.io/kaidante) on keybase.
  • I have a public key ASBFipg0ptLW0OW8T3vdEsxHOxpMLJ7zkFn9A8iyR-j5yAo

To claim this, I am signing this object: