From 409b76a88e589cbd7a8dfd9d0aad8152bb00d0bb Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 20 Nov 2025 21:43:16 +0100 Subject: feature: implemented some basic benchmarking logic & enum for pass and test --- src/main/scala/com/nsrddyn/ALU/Hash.scala | 31 +++++++++++++++ src/main/scala/com/nsrddyn/ALU/Prime.scala | 41 ++++++++++++++++++++ src/main/scala/com/nsrddyn/Enums/Status.scala | 6 +++ .../com/nsrddyn/FPU/CholeskyDecomposition.scala | 26 +++++++++++++ src/main/scala/com/nsrddyn/FPU/FPU.scala | 6 +++ src/main/scala/com/nsrddyn/FPU/Matrix.scala | 5 +++ src/main/scala/com/nsrddyn/Main.scala | 12 +----- src/main/scala/com/nsrddyn/cpu/ALU/Hash.scala | 31 --------------- src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala | 45 ---------------------- .../nsrddyn/cpu/FPU/CholeskyDecomposition.scala | 28 -------------- src/main/scala/com/nsrddyn/cpu/FPU/FPU.scala | 6 --- src/main/scala/com/nsrddyn/cpu/FPU/Matrix.scala | 5 --- 12 files changed, 116 insertions(+), 126 deletions(-) create mode 100644 src/main/scala/com/nsrddyn/ALU/Hash.scala create mode 100644 src/main/scala/com/nsrddyn/ALU/Prime.scala create mode 100644 src/main/scala/com/nsrddyn/Enums/Status.scala create mode 100644 src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala create mode 100644 src/main/scala/com/nsrddyn/FPU/FPU.scala create mode 100644 src/main/scala/com/nsrddyn/FPU/Matrix.scala delete mode 100644 src/main/scala/com/nsrddyn/cpu/ALU/Hash.scala delete mode 100644 src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala delete mode 100644 src/main/scala/com/nsrddyn/cpu/FPU/CholeskyDecomposition.scala delete mode 100644 src/main/scala/com/nsrddyn/cpu/FPU/FPU.scala delete mode 100644 src/main/scala/com/nsrddyn/cpu/FPU/Matrix.scala (limited to 'src/main/scala') diff --git a/src/main/scala/com/nsrddyn/ALU/Hash.scala b/src/main/scala/com/nsrddyn/ALU/Hash.scala new file mode 100644 index 0000000..9dc5a98 --- /dev/null +++ b/src/main/scala/com/nsrddyn/ALU/Hash.scala @@ -0,0 +1,31 @@ +package com.nsrddyn.alu + +import scala.util.hashing + +class Hash { + +import scala.util.hashing.MurmurHash3 + + 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) + + } +} diff --git a/src/main/scala/com/nsrddyn/ALU/Prime.scala b/src/main/scala/com/nsrddyn/ALU/Prime.scala new file mode 100644 index 0000000..343dcee --- /dev/null +++ b/src/main/scala/com/nsrddyn/ALU/Prime.scala @@ -0,0 +1,41 @@ +package com.nsrddyn.alu + + +import com.nsrddyn.tools.Benchmark + +class Prime() extends Benchmark { + + /* + * 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 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") + + } + + +} + diff --git a/src/main/scala/com/nsrddyn/Enums/Status.scala b/src/main/scala/com/nsrddyn/Enums/Status.scala new file mode 100644 index 0000000..79b140c --- /dev/null +++ b/src/main/scala/com/nsrddyn/Enums/Status.scala @@ -0,0 +1,6 @@ +package com.nsrddyn.Enums + +enum Status: + case PASS + case FAIL + diff --git a/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala b/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala new file mode 100644 index 0000000..b42ade9 --- /dev/null +++ b/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala @@ -0,0 +1,26 @@ +package com.nsrddyn.fpu + + +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/ + * + * + */ + + def choleskyDecomposition(n: Int): Unit = { + + for (w <- 0 to n) { + + + } + } +} diff --git a/src/main/scala/com/nsrddyn/FPU/FPU.scala b/src/main/scala/com/nsrddyn/FPU/FPU.scala new file mode 100644 index 0000000..6532476 --- /dev/null +++ b/src/main/scala/com/nsrddyn/FPU/FPU.scala @@ -0,0 +1,6 @@ +package com.nsrddyn.fpu + + +class FPU { + +} diff --git a/src/main/scala/com/nsrddyn/FPU/Matrix.scala b/src/main/scala/com/nsrddyn/FPU/Matrix.scala new file mode 100644 index 0000000..7f1bccf --- /dev/null +++ b/src/main/scala/com/nsrddyn/FPU/Matrix.scala @@ -0,0 +1,5 @@ +package com.nsrddyn.fpu + +class Matrix { + +} diff --git a/src/main/scala/com/nsrddyn/Main.scala b/src/main/scala/com/nsrddyn/Main.scala index aedad3c..de4fa1b 100644 --- a/src/main/scala/com/nsrddyn/Main.scala +++ b/src/main/scala/com/nsrddyn/Main.scala @@ -8,19 +8,9 @@ object Torque { @main def main(args: String*): Unit = - val pr = new Prime() - val br = new Benchmark() - // ANSI ESCAPE CODE: clear screen println("\u001b[2J\u001b[H") println("--- TORQUE STRESS TESTING UTILITY ---") - // val value = 2147483647 - val value = 200000 - - val time = br.measure(pr.run(value)) - println(time) - -} - + } diff --git a/src/main/scala/com/nsrddyn/cpu/ALU/Hash.scala b/src/main/scala/com/nsrddyn/cpu/ALU/Hash.scala deleted file mode 100644 index 9dc5a98..0000000 --- a/src/main/scala/com/nsrddyn/cpu/ALU/Hash.scala +++ /dev/null @@ -1,31 +0,0 @@ -package com.nsrddyn.alu - -import scala.util.hashing - -class Hash { - -import scala.util.hashing.MurmurHash3 - - 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) - - } -} diff --git a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala deleted file mode 100644 index effedef..0000000 --- a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala +++ /dev/null @@ -1,45 +0,0 @@ -package com.nsrddyn.alu - - -import com.nsrddyn.tools.Benchmark - -class Prime() extends Benchmark: - - /* - * 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 isPrime(n: Int): Boolean = { - val start = measure() - if n <= 1 then false - else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0) - } - - def run(n: Int): Unit = for i <- 0 to n do isPrime(i) - - - // TODO: implement measure methode to measure the time that it takes to find that prime number - def measure(): Long ={ - - val start = System.nanoTime() - System.nanoTime() - val end = System.nanoTime() - start - end - } - diff --git a/src/main/scala/com/nsrddyn/cpu/FPU/CholeskyDecomposition.scala b/src/main/scala/com/nsrddyn/cpu/FPU/CholeskyDecomposition.scala deleted file mode 100644 index 79325f4..0000000 --- a/src/main/scala/com/nsrddyn/cpu/FPU/CholeskyDecomposition.scala +++ /dev/null @@ -1,28 +0,0 @@ -package com.nsrddyn.fpu - - -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/ - * - * - */ - - def choleskyDecomposition(n: Int): Unit = { - - for (w <- 0 to n) { - - - } - } - - -} diff --git a/src/main/scala/com/nsrddyn/cpu/FPU/FPU.scala b/src/main/scala/com/nsrddyn/cpu/FPU/FPU.scala deleted file mode 100644 index 6532476..0000000 --- a/src/main/scala/com/nsrddyn/cpu/FPU/FPU.scala +++ /dev/null @@ -1,6 +0,0 @@ -package com.nsrddyn.fpu - - -class FPU { - -} diff --git a/src/main/scala/com/nsrddyn/cpu/FPU/Matrix.scala b/src/main/scala/com/nsrddyn/cpu/FPU/Matrix.scala deleted file mode 100644 index 7f1bccf..0000000 --- a/src/main/scala/com/nsrddyn/cpu/FPU/Matrix.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.nsrddyn.fpu - -class Matrix { - -} -- cgit v1.2.3-70-g09d2