Skip to content

Instantly share code, notes, and snippets.

@Mekk
Created January 13, 2010 10:58
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 Mekk/276105 to your computer and use it in GitHub Desktop.
Save Mekk/276105 to your computer and use it in GitHub Desktop.
object Speed {
val N = 10000
val M = 1000
def calc():Double = {
val step = 20.0 / N
val total = ((0 until N) map { step * _ - 10.0 }
map { x => Math.pow(Math.E,-x*x) * step }
reduceLeft { _ + _ })
total
}
def main(args: Array[String]) = {
val start: Long = System.currentTimeMillis();
val total: Double = ((0 until M) map { x => calc }
reduceLeft { _ + _ })
println( (System.currentTimeMillis() - start) / (M*1.0) )
println( "Wynik: " + calc() + " (razem " + total + ")" )
}
}
/* Pozwala uruchomić przez "scala skrypt.scala", przy kompilowaniu wyrzucić */
Speed main(Array())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment