mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
feature(updatefeature(update): prime calculation method
finished the prime number calculation method, added an example of it calculating the max int number. stresses cpu usage to 100%, not heavy yet. But we are stressing it in someway. next steps are to add multithreading and different ways of performance measurments.
This commit is contained in:
parent
a66ec9fb87
commit
94e2465ded
@ -1,15 +1,20 @@
|
||||
package com.nsrddyn
|
||||
|
||||
|
||||
object Torque {
|
||||
|
||||
import com.nsrddyn
|
||||
import java.time.Instant
|
||||
|
||||
@main def HelloWorld(args: String*): Unit =
|
||||
println("--- TORQUE STRESS TESTING UTILITY")
|
||||
val prime = new Prime()
|
||||
@main def main(args: String*): Unit =
|
||||
|
||||
prime.run(3, 5)
|
||||
// ANSI ESCAPE CODE: clear screen
|
||||
println("\u001b[2J\u001b[H")
|
||||
println("--- TORQUE STRESS TESTING UTILITY ---")
|
||||
|
||||
val now: Instant = Instant.now()
|
||||
println(now)
|
||||
|
||||
val pr = new Prime(4)
|
||||
|
||||
val intMax = 2147483647
|
||||
pr.run(intMax)
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ package com.nsrddyn
|
||||
|
||||
class Prime(threads: Int) {
|
||||
|
||||
|
||||
/*
|
||||
* Calculate all primes up to limit
|
||||
* This should stress the ALU in someway,
|
||||
@ -11,36 +12,17 @@ class Prime(threads: Int) {
|
||||
* will hopefully keep the cpu pipeline busy
|
||||
* and that way stress the branch predictor
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
// TODO: bad implementation of scala, scala prefers functional programming which something I am not doing here
|
||||
|
||||
def run(n: Long): Unit = {
|
||||
|
||||
|
||||
var iterator = 0
|
||||
|
||||
// TODO: run the isPrime checks
|
||||
|
||||
}
|
||||
* math.sqrt(n) => a prime number has 2 factors, one of the factors
|
||||
* of the prime numbers has to be smaller then n
|
||||
* after that we check if the number is whole number and thereby checking if its a prime
|
||||
*
|
||||
*/
|
||||
|
||||
def isPrime(n: Int): Boolean = {
|
||||
|
||||
for
|
||||
i <- 2 to 5
|
||||
if isWholeNumber(n % i) == true then
|
||||
true
|
||||
|
||||
false
|
||||
|
||||
// TODO: calculate if the number is a prime number
|
||||
// TODO: fix errors
|
||||
if n <= 1 then false
|
||||
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
||||
}
|
||||
|
||||
def isWholeNumber(n: Int | Float): Boolean = {
|
||||
// TODO: calculate if the number is a whole number
|
||||
def run(n: Int): Unit = for i <- 0 to n do isPrime(i)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user