mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
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:
parent
308f6addd0
commit
4bb2ff6828
@ -3,6 +3,7 @@ package com.nsrddyn
|
|||||||
object Torque {
|
object Torque {
|
||||||
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import com.nsrddyn.alu.*
|
||||||
|
|
||||||
@main def main(args: String*): Unit =
|
@main def main(args: String*): Unit =
|
||||||
|
|
||||||
@ -15,6 +16,12 @@ object Torque {
|
|||||||
|
|
||||||
val pr = new Prime()
|
val pr = new Prime()
|
||||||
|
|
||||||
|
/*
|
||||||
val intMax = 2147483647
|
val intMax = 2147483647
|
||||||
pr.run(intMax)
|
pr.run(intMax)
|
||||||
|
*/
|
||||||
|
|
||||||
|
val intMax = 2147483647
|
||||||
|
println(pr.measure())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
* 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 = {
|
def isPrime(n: Int): Boolean = {
|
||||||
if n <= 1 then false
|
if n <= 1 then false
|
||||||
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
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 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()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
5
src/main/scala/com/nsrddyn/tools/Measurable.scala
Normal file
5
src/main/scala/com/nsrddyn/tools/Measurable.scala
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.nsrddyn.tools
|
||||||
|
|
||||||
|
trait Measurable {
|
||||||
|
def measure(): Long
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user