Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
def task(n: Int) = Thread.sleep(n * 1000)
def rate(fs: List[() => Unit]) = {
val jobs = fs map (f => scala.actors.Futures.future(f()))
val cnt1 = scala.actors.Futures.awaitAll(5000, jobs: _*).count(_ != None)
val cnt2 = scala.actors.Futures.awaitAll(5000, jobs: _*).count(_ != None)
val cnt3 = scala.actors.Futures.awaitAll(5000, jobs: _*).count(_ != None)
println("%d jobs in 5 seconds" format cnt1)
println("%d jobs in 10 seconds" format cnt2)
println("%d jobs in 15 seconds" format cnt3)
}
rate(List.fill(30)(() => task(scala.util.Random.nextInt(10)+1)))

View file

@ -0,0 +1,15 @@
def rate(n: Int, y: Int)(task: => Unit) {
val startTime = System.currentTimeMillis
var currTime = startTime
var loops = 0
do {
task
currTime = System.currentTimeMillis
loops += 1
} while (currTime - startTime < n * 1000 && loops < y)
if (currTime - startTime > n * 1000)
println("Rate %d times per %d seconds" format (loops - 1, n))
else
println("Rate %d times in %.3f seconds" format (y, (currTime - startTime).toDouble / 1000))
}
rate(5, 20)(task(2))