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 package main.Ops
import com.nsrddyn.tools.Benchmark
import main.tools.Benchmark
import main.Traits.*
import scala.util.hashing import scala.util.hashing
import scala.util.hashing.MurmurHash3 import scala.util.hashing.MurmurHash3
import com.nsrddyn.Traits.*
import scala.math._ import scala.math._
import scala.collection.immutable.ListSet import scala.collection.immutable.ListSet
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
@ -29,47 +31,17 @@ class Prime() {
* We want the function to be less optimized so that the CPU has more work == more stress * 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 = { def run(n: Int, result: Boolean): Unit = {
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false") 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 { class Hash {
def run(word: String, loopSize: Int): Unit = { def run(word: String, loopSize: Int): Unit = {
@ -91,7 +63,7 @@ class Hash {
* *
*/ */
for i <- 0 to loopSize do MurmurHash3.stringHash(word) for i <- 0 to loopSize do MurmurHash3.stringHash(word)
} }
} }
@ -121,10 +93,10 @@ class CholeskyDecomposition {
val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]() val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
for for
i <- 0 to size i <- 0 to size
j <- 0 until i j <- 0 until i
do do
if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix) if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
} }

View File

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

View File

@ -1,4 +1,6 @@
package com.nsrddyn.tools package main.tools
import main.Ops.*
class Benchmark { class Benchmark {
/* /*
@ -15,3 +17,26 @@ class Benchmark {
// TODO: map this to an actual precision value // TODO: map this to an actual precision value
def measurePrecision(work: => Boolean, expectedResult: Boolean): Unit = if work == expectedResult then println(true) else println(false) 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 { trait Workload {