diff options
Diffstat (limited to 'src/main/scala/com/nsrddyn/cpu')
| -rw-r--r-- | src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala b/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala index 47c83f1..effedef 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.alu -import com.nsrddyn.tools.Measurable +import com.nsrddyn.tools.Benchmark -class Prime() extends Measurable: +class Prime() extends Benchmark: /* * Calculate all primes up to limit @@ -24,17 +24,22 @@ class Prime() extends Measurable: * 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) - def measure(): Long = { - - // TODO: implement measure methode to measure the time that it takes to find that prime number + + // 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 } |
