Compare commits

..

2 Commits

7 changed files with 92 additions and 86 deletions

View File

View File

@ -1,30 +0,0 @@
package com.nsrddyn
import com.nsrddyn.fpu.CholeskyDecomposition
import com.nsrddyn.Tests.CholeskyDecompositionTest
import java.time.Instant
import com.nsrddyn.alu.*
import com.nsrddyn.tools.Benchmark
enum Status:
case PASS
case FAIL
object Torque extends ZIOAppDefault {
println("hello world")
@main def main(args: String*): Unit = { println("\u001b[2J\u001b[H")
println("--- TORQUE STRESS TESTING UTILITY ---")
var tester: CholeskyDecompositionTest = new CholeskyDecompositionTest
println(tester.test())
}
var p: Prime = new Prime
p.run()
}

View File

@ -0,0 +1,43 @@
package main
import Ops.*
import Tests.*
import java.time.Instant
import zio._
/*
* *> = "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)
* */
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
}

View File

@ -1,8 +1,10 @@
package com.nsrddyn.ops
import com.nsrddyn.tools.Benchmark
package main.Ops
import main.tools.Benchmark
import main.Traits.*
import scala.util.hashing
import scala.util.hashing.MurmurHash3
import com.nsrddyn.Traits.*
import scala.math._
import scala.collection.immutable.ListSet
import scala.collection.mutable.ArrayBuffer
@ -29,46 +31,16 @@ 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 PrimeRunner {
def run(threads: Int): Unit = {
val pr = new Prime()
val br = new Benchmark()
/*
* test cases
*
* 7919 true
* 2147483647 false
*/
val time = pr.run(7919, true)
println(time)
}
}
class Hash {

View File

@ -1,18 +1,11 @@
package com.nsrddyn.Tests
package main.Tests
import com.nsrddyn.fpu.CholeskyDecomposition
import scala.collection.immutable.ListSet
import zio._
class TestsRunner extends ZIOAppDefault {
def run =
println("Hello world")
import main.Ops.CholeskyDecomposition
}
class CholeskyDecompositionTest {
class CholeskyDecompositionRunner {
def test(): Unit = {
@ -22,7 +15,4 @@ class CholeskyDecompositionTest {
println(cdp.run(matrix))
}
}

View File

@ -1,4 +1,6 @@
package com.nsrddyn.tools
package main.tools
import main.Ops.*
class Benchmark {
/*
@ -15,3 +17,26 @@ class Benchmark {
// TODO: map this to an actual precision value
def measurePrecision(work: => Boolean, expectedResult: Boolean): Unit = if work == expectedResult then println(true) else println(false)
}
class PrimeRunner {
def run(threads: Int): Unit = {
val pr = new Prime()
val br = new Benchmark()
/*
* test cases
*
* 7919 true
* 2147483647 false
*/
val time = pr.run(7919, true)
println(time)
}
}

View File

@ -1,4 +1,10 @@
package com.nsrddyn.Traits
package main.Traits
import zio._
enum Status:
case PASS
case FAIL
trait Workload {