Skip to content

Instantly share code, notes, and snippets.

@JD557
Created September 17, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JD557/3acf3d426c21f66fd9e8e25ab21813fe to your computer and use it in GitHub Desktop.
Save JD557/3acf3d426c21f66fd9e8e25ab21813fe to your computer and use it in GitHub Desktop.
/*
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