mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
feature: basic zio concurrency
This commit is contained in:
parent
356d86e2a9
commit
fe6dc1d84b
@ -2,21 +2,42 @@ package main
|
||||
|
||||
import Ops.*
|
||||
import Tests.*
|
||||
import tools.*
|
||||
|
||||
import java.time.Instant
|
||||
import zio._
|
||||
|
||||
object Torque {
|
||||
|
||||
@main
|
||||
def main(args: String*): Unit = { println("\u001b[2J\u001b[H")
|
||||
println("--- TORQUE STRESS TESTING UTILITY ---")
|
||||
/*
|
||||
* *> = "Then" (think arrow pointing to what matters)
|
||||
* <&> = "Both" (symbol looks like things going in both directions)
|
||||
* <* = "Keep left" (pointing to what you keep)
|
||||
* &> = "Keep right" (pointing to what you keep)
|
||||
* */
|
||||
|
||||
var cdt: CholeskyDecompositionTest = new CholeskyDecompositionTest
|
||||
// returns an out of bounds error
|
||||
// println(cdt.test())
|
||||
var p: Prime = new Prime
|
||||
p.run(1000000000, true)
|
||||
object Torque extends ZIOAppDefault {
|
||||
|
||||
}
|
||||
def runCholeskyTest: ZIO[Any, Throwable, Unit] =
|
||||
ZIO.attempt {
|
||||
val matrix: Vector[Vector[Int]] = Vector(Vector(1,2,3), Vector(1,2,3), Vector(1,2,3))
|
||||
val cd = new CholeskyDecomposition
|
||||
cd.run(matrix)
|
||||
}.catchAll { error => Console.printError(s"failed: $error")}
|
||||
|
||||
def runPrimeTest: ZIO[Any, Throwable, Unit] =
|
||||
ZIO.attempt {
|
||||
val p = new Prime
|
||||
p.run(390483094, true)
|
||||
}.catchAll { error => Console.printError(s"failed: $error")}
|
||||
|
||||
def runSequential: ZIO[Any, Throwable, Unit] =
|
||||
Console.printLine("sequential test") *>
|
||||
runCholeskyTest *>
|
||||
runPrimeTest
|
||||
|
||||
def runParallel: ZIO[Any, Throwable, Unit] =
|
||||
Console.printLine("CholeskyTest") *>
|
||||
(runCholeskyTest <&> runPrimeTest).unit
|
||||
|
||||
override def run: ZIO[ZIOAppArgs & Scope, Any, Any] = runParallel
|
||||
}
|
||||
|
||||
|
||||
@ -31,18 +31,15 @@ class Prime() {
|
||||
* We want the function to be less optimized so that the CPU has more work == more stress
|
||||
*/
|
||||
|
||||
|
||||
def isPrime(n: Int): Boolean = {
|
||||
if n <= 1 then false
|
||||
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
||||
|
||||
|
||||
}
|
||||
|
||||
def run(n: Int, result: Boolean): Unit = {
|
||||
|
||||
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
|
||||
}
|
||||
|
||||
private def isPrime(n: Int): Boolean = {
|
||||
if n <= 1 then false
|
||||
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Hash {
|
||||
|
||||
@ -5,7 +5,7 @@ import zio._
|
||||
import main.Ops.CholeskyDecomposition
|
||||
|
||||
|
||||
class CholeskyDecompositionTest {
|
||||
class CholeskyDecompositionRunner {
|
||||
|
||||
def test(): Unit = {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user