summaryrefslogtreecommitdiff
path: root/src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2025-11-20 18:45:53 +0100
committernasr <nsrddyn@gmail.com>2025-11-20 18:45:53 +0100
commit421c6c3c93c4f68c808aaabc6b2d8fac06674321 (patch)
tree030dee368e76f09ef56a183d021d10e7bdc5c435 /src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala
parent4bb2ff6828e344c0c1398f9ac5ddb318948c4a47 (diff)
feature[benchmark]: time measurement benchmark
not a good way of testing things, but it's a way and the first way
Diffstat (limited to 'src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala')
-rw-r--r--src/main/scala/com/nsrddyn/cpu/ALU/Prime.scala17
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
}