Created
January 13, 2010 10:58
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
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