Skip to content

Instantly share code, notes, and snippets.

@crakjie
Last active February 15, 2016 22:16
Show Gist options
  • Save crakjie/d4fa0f53bc22e5f63590 to your computer and use it in GitHub Desktop.
Save crakjie/d4fa0f53bc22e5f63590 to your computer and use it in GitHub Desktop.
Elapsed time of a piece of code
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
def time[T](f: => T, message: String = "" ): T = {
val a = System.currentTimeMillis()
val r = f
val b = System.currentTimeMillis()
Future { println(message + " elapsed time :"+ (b - a) + "ms" + Console.RESET )}
r
}
@crakjie
Copy link
Author

crakjie commented Oct 29, 2014

Console.RESET is usefull to reset color to default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment