From 4bb2ff6828e344c0c1398f9ac5ddb318948c4a47 Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Wed, 19 Nov 2025 15:01:14 +0100 Subject: feature: performance measuring to be implemented in prime generator - created new prime class - measures performance based on time ( for now ) - needs further implementation --- src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/main/scala/com/nsrddyn/cpu') diff --git a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala index 3e6ad6f..47c83f1 100644 --- a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala +++ b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala @@ -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() + + } -- cgit v1.2.3-70-g09d2