Last active
November 22, 2024 11:30
-
-
Save regiskuckaertz/4fd8c9055b92608c4c9bc0639a760b55 to your computer and use it in GitHub Desktop.
A scala-cli script for the "1 Billion nested loop iterations" experiment
This file contains hidden or 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
//> platform native | |
@scala.annotation.tailrec | |
def loop(n: Int, i: Int = 0)(f: Int => Any): Unit = | |
if i < n then | |
f(i) | |
loop(n, i + 1)(f) | |
else () | |
@main def run(u: Int) = | |
val r = scala.util.Random.nextInt(10000) | |
val a = Array.fill(10000)(0) | |
loop(10_000) { i => | |
loop(100_000) { j => | |
a(i) += u | |
} | |
a(i) += r | |
} | |
println(s"${a(r)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled using: