feature: performance measuring to be implemented in prime generator

- created new prime class
- measures performance based on time ( for now )
- needs further implementation
This commit is contained in:
Abdellah El Morabit 2025-11-19 15:01:14 +01:00
parent 308f6addd0
commit 4bb2ff6828
3 changed files with 28 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package com.nsrddyn
object Torque {
import java.time.Instant
import com.nsrddyn.alu.*
@main def main(args: String*): Unit =
@ -15,6 +16,12 @@ object Torque {
val pr = new Prime()
/*
val intMax = 2147483647
pr.run(intMax)
*/
val intMax = 2147483647
println(pr.measure())
}

View File

@ -1,9 +1,9 @@
package com.nsrddyn
package com.nsrddyn.alu
import com.nsrddyn.tools.Measurable
class Prime() {
class Prime() extends Measurable:
/*
* Calculate all primes up to limit
@ -18,11 +18,23 @@ class 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): Unit = for i <- 0 to n do isPrime(i)
}
def measure(): Long = {
// TODO: implement measure methode to measure the time that it takes to find that prime number
System.nanoTime()
}

View File

@ -0,0 +1,5 @@
package com.nsrddyn.tools
trait Measurable {
def measure(): Long
}