Last active
February 3, 2024 14:35
-
-
Save chemacortes/a4e25af1fed81e3d097eb75e44779f79 to your computer and use it in GitHub Desktop.
Benchmarks in scala
This file contains 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 characters
def benchmarks[A](f: => A) = | |
inline def memory() = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() | |
val t0 = System.nanoTime() | |
val m0 = memory() | |
val ret = f | |
val t1 = System.nanoTime() | |
val m1 = memory() | |
println(s"time: ${(t1-t0) / 1e6} ms") | |
println(s"mem: ${(m1-m0) / 1_000_000_000.0} GB") | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment