-
-
Save JD557/3acf3d426c21f66fd9e8e25ab21813fe to your computer and use it in GitHub Desktop.
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
/* | |
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