summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/main/Main.scala14
-rw-r--r--src/main/scala/main/Ops/Ops.scala109
-rw-r--r--src/main/scala/main/Tests/Tests.scala14
-rw-r--r--src/main/scala/main/domain/CpuOperations.scala118
-rw-r--r--src/main/scala/main/domain/MemoryOperations.scala40
-rw-r--r--src/main/scala/main/infrastructure/Http.scala (renamed from src/main/scala/main/Http/Http.scala)11
-rw-r--r--src/main/scala/main/infrastructure/Resources.scala (renamed from src/main/scala/main/Ops/Resources.scala)8
-rw-r--r--src/main/scala/main/services/Benchmark.scala (renamed from src/main/scala/main/Tools/Benchmark.scala)29
-rw-r--r--src/main/scala/main/services/Stress.scala (renamed from src/main/scala/main/Tools/Runner.scala)15
9 files changed, 185 insertions, 173 deletions
diff --git a/src/main/scala/main/Main.scala b/src/main/scala/main/Main.scala
index 2ee9d9a..1406fc0 100644
--- a/src/main/scala/main/Main.scala
+++ b/src/main/scala/main/Main.scala
@@ -1,20 +1,12 @@
package main
-import main.Ops.*
-import main.Tests.*
-import main.Tools.*
-import main.Runner.*
+import main.domain._
+import main.services._
+import main.infrastructure._
import oshi._
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 run: ZIO[ZIOAppArgs & Scope, Any, Any] = {
diff --git a/src/main/scala/main/Ops/Ops.scala b/src/main/scala/main/Ops/Ops.scala
deleted file mode 100644
index 214b824..0000000
--- a/src/main/scala/main/Ops/Ops.scala
+++ /dev/null
@@ -1,109 +0,0 @@
-package main.Ops
-
-import main.Tools.*
-
-import scala.util.hashing
-import scala.util.hashing.MurmurHash3
-import scala.math._
-import scala.collection.immutable.ListSet
-import scala.collection.mutable.ArrayBuffer
-
-
-class Prime() {
-
- /*
- * Calculate all primes up to limit
- * This should stress the ALU in someway,
- * doing this in a predictable manner,
- * will hopefully keep the cpu pipeline busy
- * and that way stress the branch predictor
- *
- * math.sqrt(n) => a prime number has 2 factors, one of the factors
- * of the prime numbers has to be smaller then n
- * after that we check if the number is whole number and thereby checking if its a prime
- *
- */
-
-
- /*
- * TODO: I did the countrary of what i wanted to accieve with the is prime function
- * We want the function to be less optimized so that the CPU has more work == more stress
- */
-
- 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 {
-
- def run(word: String, loopSize: Int): Unit = {
-
- /* TODO: implement ALU friendly, so high speed hashing
- * to continuously loop over voor stressing
- * ALU
- *
- * While looking for hashing algorithmes to implement I stumbled on:
- * https://scala-lang.org/api/3.x/scala/util/hashing/MurmurHash3$.html
- *
- * which is an implemntation of **smasher** http://github.com/aappleby/smhasher
- * the exact type of hashing algorithm I was looking for
- *
- * In the scala description they state: "This algorithm is designed to generate
- * well-distributed non-cryptographic hashes. It is designed to hash data in 32 bit chunks (ints). "
- *
- * (ints) -> ALU
- *
- */
-
- for i <- 0 to loopSize do MurmurHash3.stringHash(word)
-
- }
-}
-
-class CholeskyDecomposition {
-
- /*
- * Floating point operation to stress the cpu
- * Calculate the number of KFLOPS / FLOPS
- * implementation of the Cholesky decomposition
- * More information on the Cholesky decomposition at:
- * https://en.wikipedia.org/wiki/Cholesky_decomposition
- *
- * Linpack uses the cholesky decomposition
- * https://www.netlib.org/linpack/
- *
- * https://www.geeksforgeeks.org/dsa/cholesky-decomposition-matrix-decomposition/
- *
- * The Cholesky decomposition maps matrix A into the product of A = L · LH where L is the lower triangular matrix and LH is the transposed,
- * complex conjugate or Hermitian, and therefore of upper triangular form (Fig. 13.6).
- * This is true because of the special case of A being a square, conjugate symmetric matrix.
- */
-
- def run(matrix: Vector[Vector[Int]]): Unit = {
-
- val size: Int = matrix.size
- val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
-
- for
- i <- 0 to size
- j <- 0 until i
- do
- if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
-
- }
-
- private def getReversedSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
- math.sqrt(matrix(j)(j) - (0 until j).map { k => lower(i)(k) * lower(j)(k) }.sum).toInt
- }
- private def getSquaredSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
- ((matrix(i)(j) - (0 until j).map { k => math.pow(lower(j)(k), 2)}.sum) / lower(j)(j)).toInt
- }
-}
-
diff --git a/src/main/scala/main/Tests/Tests.scala b/src/main/scala/main/Tests/Tests.scala
deleted file mode 100644
index 93c21a6..0000000
--- a/src/main/scala/main/Tests/Tests.scala
+++ /dev/null
@@ -1,14 +0,0 @@
-package main.Tests
-
-import main.Ops.*
-import main.Tools.*
-import zio._
-import scala.collection.immutable.ListSet
-
-class Test {
-
- def run(): Unit = {
-
-
- }
-}
diff --git a/src/main/scala/main/domain/CpuOperations.scala b/src/main/scala/main/domain/CpuOperations.scala
new file mode 100644
index 0000000..ebc5c9b
--- /dev/null
+++ b/src/main/scala/main/domain/CpuOperations.scala
@@ -0,0 +1,118 @@
+package main.domain
+
+import main.services._
+
+import scala.util.hashing
+import scala.util.hashing.MurmurHash3
+import scala.math._
+import scala.collection.immutable.ListSet
+import scala.collection.mutable.ArrayBuffer
+
+
+trait CPU {
+
+
+}
+
+
+ /*
+ * Calculate all primes up to limit
+ * This should stress the ALU in someway,
+ * doing this in a predictable manner,
+ * will hopefully keep the cpu pipeline busy
+ * and that way stress the branch predictor
+ *
+ * math.sqrt(n) => a prime number has 2 factors, one of the factors
+ * of the prime numbers has to be smaller then n
+ * after that we check if the number is whole number and thereby checking if its a prime
+ *
+ */
+
+
+ /*
+ * TODO: I did the countrary of what i wanted to accieve with the is prime function
+ * We want the function to be less optimized so that the CPU has more work == more stress
+ */
+
+class Prime extends CPU {
+
+ def run(n: Int): Unit = {
+ for i <- 0 to n do if isPrime(i) == true 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)
+ }
+
+}
+
+
+/* TODO: implement ALU friendly, so high speed hashing
+ * to continuously loop over voor stressing
+ * ALU
+ *
+ * While looking for hashing algorithmes to implement I stumbled on:
+ * https://scala-lang.org/api/3.x/scala/util/hashing/MurmurHash3$.html
+ *
+ * which is an implemntation of **smasher** http://github.com/aappleby/smhasher
+ * the exact type of hashing algorithm I was looking for
+ *
+ * In the scala description they state: "This algorithm is designed to generate
+ * well-distributed non-cryptographic hashes. It is designed to hash data in 32 bit chunks (ints). "
+ *
+ * (ints) -> ALU
+ *
+ */
+
+class Hash extends CPU {
+
+ def run(n: Int): Unit = {
+
+ for i <- 0 to n do MurmurHash3.stringHash("a random string to hash")
+
+ }
+}
+
+/*
+ * Floating point operation to stress the cpu
+ * Calculate the number of KFLOPS / FLOPS
+ * implementation of the Cholesky decomposition
+ * More information on the Cholesky decomposition at:
+ * https://en.wikipedia.org/wiki/Cholesky_decomposition
+ *
+ * Linpack uses the cholesky decomposition
+ * https://www.netlib.org/linpack/
+ *
+ * https://www.geeksforgeeks.org/dsa/cholesky-decomposition-matrix-decomposition/
+ *
+ * The Cholesky decomposition maps matrix A into the product of A = L · LH where L is the lower triangular matrix and LH is the transposed,
+ * complex conjugate or Hermitian, and therefore of upper triangular form (Fig. 13.6).
+ * This is true because of the special case of A being a square, conjugate symmetric matrix.
+ */
+
+class CholeskyDecomposition extends CPU {
+
+
+ def run(matrix: Vector[Vector[Int]]): Unit = {
+
+ val size: Int = matrix.size
+ val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
+
+ for
+ i <- 0 to size
+ j <- 0 until i
+ do
+ if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
+
+ }
+
+ private def getReversedSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
+ math.sqrt(matrix(j)(j) - (0 until j).map { k => lower(i)(k) * lower(j)(k) }.sum).toInt
+ }
+ private def getSquaredSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
+ ((matrix(i)(j) - (0 until j).map { k => math.pow(lower(j)(k), 2)}.sum) / lower(j)(j)).toInt
+ }
+}
+
+
diff --git a/src/main/scala/main/domain/MemoryOperations.scala b/src/main/scala/main/domain/MemoryOperations.scala
new file mode 100644
index 0000000..464d0bc
--- /dev/null
+++ b/src/main/scala/main/domain/MemoryOperations.scala
@@ -0,0 +1,40 @@
+package main.domain
+
+import main.services._
+
+import scala.util.hashing
+import scala.util.hashing.MurmurHash3
+import scala.math._
+import scala.collection.immutable.ListSet
+import scala.collection.mutable.ArrayBuffer
+
+/**
+ *
+ * Large memory object to allocate on the heap
+ * This is an implementation by me
+ *
+ * */
+
+sealed Trait MemoryObject {
+
+
+}
+
+class MemoryAllocater {
+
+ /*
+ *
+ * for stressing the memory we want to do some heavy heap allocations back and forth
+ *
+ * */
+
+ def run(): Unit = println("stressing memory")
+
+
+ def moveToMemory(): Unit ={
+
+ }
+}
+
+
+
diff --git a/src/main/scala/main/Http/Http.scala b/src/main/scala/main/infrastructure/Http.scala
index a56a563..cf9a6e1 100644
--- a/src/main/scala/main/Http/Http.scala
+++ b/src/main/scala/main/infrastructure/Http.scala
@@ -1,9 +1,16 @@
+package main.infrastructure
+
import zio._
import zio.http._
-// https://ziohttp.com/
+/**
+ * HTTP Handler
+ * using ZIO
+ *
+ *
+ * source: https://ziohttp.com */
-object GreetingServer extends ZIOAppDefault {
+object Greeter extends ZIOAppDefault {
val routes =
Routes(
Method.GET / "stability" -> handler { (req: Request) =>
diff --git a/src/main/scala/main/Ops/Resources.scala b/src/main/scala/main/infrastructure/Resources.scala
index cd9cade..f4e88c2 100644
--- a/src/main/scala/main/Ops/Resources.scala
+++ b/src/main/scala/main/infrastructure/Resources.scala
@@ -1,8 +1,8 @@
-package main.Resources
+package main.infrastructure
-import main.Ops.*
-import main.Tests.*
-import main.Tools.*
+import main.domain._
+import main.services._
+import main.infrastructure._
import oshi._
import zio._
diff --git a/src/main/scala/main/Tools/Benchmark.scala b/src/main/scala/main/services/Benchmark.scala
index 04b9861..59c81e9 100644
--- a/src/main/scala/main/Tools/Benchmark.scala
+++ b/src/main/scala/main/services/Benchmark.scala
@@ -1,10 +1,8 @@
-package main.Tools
+package main.services
-import main.Ops.*
-import main.Tests.*
-import main.Tools.*
-import oshi._
+import main.domain._
import java.time.Instant
+import oshi._
class Benchmark {
/*
@@ -23,24 +21,3 @@ class Benchmark {
}
-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)
-
- }
-}
-
diff --git a/src/main/scala/main/Tools/Runner.scala b/src/main/scala/main/services/Stress.scala
index 384ec5d..3709378 100644
--- a/src/main/scala/main/Tools/Runner.scala
+++ b/src/main/scala/main/services/Stress.scala
@@ -1,15 +1,16 @@
-package main.Runner
+package main.services
-import main.Ops.*
-import main.Tests.*
-import main.Tools.*
+import main.domain._
+import main.services._
import oshi._
import zio._
-class Runner {
- val p = new Prime
- val cd = new CholeskyDecomposition
+enum Status:
+ case PASS
+ case FAIL
+
+class Stress(val status: Status) {
def runCholeskyTest: ZIO[Any, Throwable, Unit] = {