mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
Compare commits
5 Commits
421c6c3c93
...
409b76a88e
| Author | SHA1 | Date | |
|---|---|---|---|
| 409b76a88e | |||
| e077e179d4 | |||
| 694f5afeff | |||
| b96c4615cd | |||
| 092f28a3f2 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,4 +10,6 @@ hs_err_pid*
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.scala-build/
|
||||||
|
|
||||||
|
project/metals.sbt
|
||||||
|
|||||||
@ -4,3 +4,4 @@ name := "torque"
|
|||||||
organization := "com.nsrddyn"
|
organization := "com.nsrddyn"
|
||||||
|
|
||||||
libraryDependencies += "dev.zio" %% "zio" % "2.1.22"
|
libraryDependencies += "dev.zio" %% "zio" % "2.1.22"
|
||||||
|
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % Test
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package com.nsrddyn.alu
|
|||||||
|
|
||||||
import com.nsrddyn.tools.Benchmark
|
import com.nsrddyn.tools.Benchmark
|
||||||
|
|
||||||
class Prime() extends Benchmark:
|
class Prime() extends Benchmark {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate all primes up to limit
|
* Calculate all primes up to limit
|
||||||
@ -26,20 +26,16 @@ class Prime() extends Benchmark:
|
|||||||
|
|
||||||
|
|
||||||
def isPrime(n: Int): Boolean = {
|
def isPrime(n: Int): Boolean = {
|
||||||
val start = measure()
|
|
||||||
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, result: Boolean): Unit = {
|
||||||
|
|
||||||
|
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
6
src/main/scala/com/nsrddyn/Enums/Status.scala
Normal file
6
src/main/scala/com/nsrddyn/Enums/Status.scala
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package com.nsrddyn.Enums
|
||||||
|
|
||||||
|
enum Status:
|
||||||
|
case PASS
|
||||||
|
case FAIL
|
||||||
|
|
||||||
@ -23,6 +23,4 @@ class CholeskyDecomposition {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -8,19 +8,9 @@ object Torque {
|
|||||||
|
|
||||||
@main def main(args: String*): Unit =
|
@main def main(args: String*): Unit =
|
||||||
|
|
||||||
val pr = new Prime()
|
|
||||||
val br = new Benchmark()
|
|
||||||
|
|
||||||
// ANSI ESCAPE CODE: clear screen
|
// ANSI ESCAPE CODE: clear screen
|
||||||
println("\u001b[2J\u001b[H")
|
println("\u001b[2J\u001b[H")
|
||||||
println("--- TORQUE STRESS TESTING UTILITY ---")
|
println("--- TORQUE STRESS TESTING UTILITY ---")
|
||||||
|
|
||||||
// val value = 2147483647
|
}
|
||||||
val value = 200000
|
|
||||||
|
|
||||||
val time = br.measure(pr.run(value))
|
|
||||||
println(time)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
29
src/main/scala/com/nsrddyn/Tests/PrimeTest.scala
Normal file
29
src/main/scala/com/nsrddyn/Tests/PrimeTest.scala
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.nsrddyn.Test
|
||||||
|
|
||||||
|
import com.nsrddyn.alu.Prime
|
||||||
|
import com.nsrddyn.tools.Benchmark
|
||||||
|
|
||||||
|
class PrimeTest extends Prime {
|
||||||
|
|
||||||
|
def runBasic(): Unit = {
|
||||||
|
|
||||||
|
val pr = new Prime()
|
||||||
|
val br = new Benchmark()
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test cases
|
||||||
|
*
|
||||||
|
* 7919 true
|
||||||
|
* 2147483647 false
|
||||||
|
*/
|
||||||
|
|
||||||
|
val time = pr.run(7919, true)
|
||||||
|
println(time)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def runExtreme(): Unit = println("running some very have stuff!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
17
src/main/scala/com/nsrddyn/Tools/Benchmark.scala
Normal file
17
src/main/scala/com/nsrddyn/Tools/Benchmark.scala
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.nsrddyn.tools
|
||||||
|
|
||||||
|
class Benchmark {
|
||||||
|
/*
|
||||||
|
* Calculate the time between the start of the execution of the function and the end
|
||||||
|
* */
|
||||||
|
def measureTime(work: => Unit): Long = {
|
||||||
|
|
||||||
|
val start = System.nanoTime()
|
||||||
|
work
|
||||||
|
val end = System.nanoTime()
|
||||||
|
end - start
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: map this to an actual precision value
|
||||||
|
def measurePrecision(work: => Boolean, expectedResult: Boolean): Unit = if work == expectedResult then println(true) else println(false)
|
||||||
|
}
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package com.nsrddyn
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cpu object, only one instance of an object needed
|
|
||||||
*/
|
|
||||||
|
|
||||||
object Cpu {
|
|
||||||
|
|
||||||
val name = ""
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package com.nsrddyn.tools
|
|
||||||
|
|
||||||
class Benchmark {
|
|
||||||
|
|
||||||
// add a reference to a function
|
|
||||||
def measure(work: => Unit): Long = {
|
|
||||||
|
|
||||||
val start = System.nanoTime()
|
|
||||||
work
|
|
||||||
val end = System.nanoTime()
|
|
||||||
end - start
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user