diff options
| author | nasr <nsrddyn@gmail.com> | 2025-11-26 23:11:25 +0100 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2025-11-26 23:11:25 +0100 |
| commit | 5c90505fe7b6566049bead5e36a5e3f73d844413 (patch) | |
| tree | d65a6402dd93d0e8ccb464eb5eab382e625a67d1 /src/main/scala/com/nsrddyn/ALU/Prime.scala | |
| parent | d6f99d058b34d5b6fbc3f630bf491b302cdf324f (diff) | |
chore: file refactor, imported zio
next steps are running the threads multithreaded and measuring for
errors
Diffstat (limited to 'src/main/scala/com/nsrddyn/ALU/Prime.scala')
| -rw-r--r-- | src/main/scala/com/nsrddyn/ALU/Prime.scala | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/main/scala/com/nsrddyn/ALU/Prime.scala b/src/main/scala/com/nsrddyn/ALU/Prime.scala deleted file mode 100644 index a6c7d15..0000000 --- a/src/main/scala/com/nsrddyn/ALU/Prime.scala +++ /dev/null @@ -1,64 +0,0 @@ -package com.nsrddyn.alu -import com.nsrddyn.alu.Prime -import com.nsrddyn.tools.Benchmark -import com.nsrddyn.test - -class Prime() extends { - - /* - * 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") - } - - -} - - - - -class PrimeRunner extends Workload { - - 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) - - } -} |
