Skip to content

Instantly share code, notes, and snippets.

@JD557

JD557/scalajs-bench.scala Secret

Created Sep 17, 2020
Embed
What would you like to do?
/*
Basic scala.js flatMap benchmarks.
Results on a 2015 Mac Book Pro
Scala.js 0.6.33/Firefox => 222ms
Scala.js 0.6.33/Chrome => 14ms
Scala.js 1.2.0/Firefox (ES 2015) => 310ms
Scala.js 1.2.0/Chrome (ES 2015) => 13ms
Scala.js 1.2.0/Firefox (ES 5.1)=> 137ms
Scala.js 1.2.0/Chrome (ES 5.1)=> 13ms
*/
package tutorial.webapp
object TutorialApp {
val numberList = List.fill(1000000)(1)
def benchmark(): Long = {
val start = System.currentTimeMillis()
numberList.foldLeft(Option(0)) {case (acc, x) => acc.flatMap(_ => Some(x))}
val end = System.currentTimeMillis()
end - start
}
def main(args: Array[String]): Unit = {
val runs = (1 to 10).map(_ => benchmark())
println("Runs: " + runs.mkString("\n"))
println("Avg: " + (runs.sum / 10))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.