mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
Compare commits
2 Commits
5c90505fe7
...
fe6dc1d84b
| Author | SHA1 | Date | |
|---|---|---|---|
| fe6dc1d84b | |||
| 356d86e2a9 |
@ -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()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
43
src/main/scala/main/Main.scala
Normal file
43
src/main/scala/main/Main.scala
Normal 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
|
||||||
|
}
|
||||||
|
|
||||||
@ -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,46 +31,16 @@ 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 {
|
||||||
|
|
||||||
@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,4 +1,10 @@
|
|||||||
package com.nsrddyn.Traits
|
package main.Traits
|
||||||
|
|
||||||
|
import zio._
|
||||||
|
|
||||||
|
enum Status:
|
||||||
|
case PASS
|
||||||
|
case FAIL
|
||||||
|
|
||||||
trait Workload {
|
trait Workload {
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user