mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
feature: implement Benchmark class and PrimeTest for performance measurement
This commit is contained in:
parent
b96c4615cd
commit
694f5afeff
@ -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
|
||||||
|
|||||||
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,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