feature: implement Benchmark class and PrimeTest for performance measurement

This commit is contained in:
Abdellah El Morabit 2025-11-20 21:41:41 +01:00
parent b96c4615cd
commit 694f5afeff
4 changed files with 47 additions and 14 deletions

View File

@ -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

View 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!")
}

View 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)
}

View File

@ -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
}
}