Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
better benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Sep 20, 2023
1 parent c74b56d commit 2aaeba2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main/scala/fsim/Simulation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Simulation(exec: Executable) {
data.boolData(clockSym.index) = false
stepCount += 1
}
def getStepCount: Int = stepCount

@inline private def updateComb(): Unit = {
if (inputPoked) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/fsim/GCDTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GCDTester extends AnyFreeSpec {
val endTime = System.nanoTime()
val elapsedSeconds = (endTime - startTime).toDouble / 1000000000.0
if (showTime) {
println(f"$elapsedSeconds%.6f seconds")
println(f"$elapsedSeconds%.6f seconds (${sim.getStepCount} cycles)")
}
}

Expand Down
42 changes: 26 additions & 16 deletions src/test/scala/treadle2/GCDTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GCDTester extends AnyFlatSpec with Matchers with LazyLogging {

behavior.of("GCD")

def sizableTest(width: Int): Unit = {
def sizableTest(width: Int, from: Long, upTo: Long, showTime: Boolean): Unit = {
val gcdFirrtl: String =
s"""
|circuit GCD :
Expand Down Expand Up @@ -58,9 +58,9 @@ class GCDTester extends AnyFlatSpec with Matchers with LazyLogging {

val values =
for {
x <- 10 to 100
y <- 10 to 100
} yield (x, y, computeGcd(x, y)._1)
x <- from to upTo
y <- from to upTo
} yield (x, y, BigInt(x).gcd(y).toLong)

TreadleTestHarness(Seq(FirrtlSourceAnnotation(gcdFirrtl))) { tester =>
val startTime = System.nanoTime()
Expand All @@ -86,12 +86,9 @@ class GCDTester extends AnyFlatSpec with Matchers with LazyLogging {
}
val endTime = System.nanoTime()
val elapsedSeconds = (endTime - startTime).toDouble / 1000000000.0

val cycle = 11 // tester.engine.circuitState.stateCounter

logger.info(
f"processed $cycle cycles $elapsedSeconds%.6f seconds ${cycle.toDouble / (1000000.0 * elapsedSeconds)}%5.3f MHz"
)
if (showTime) {
println(f"$elapsedSeconds%.6f seconds")
}
}
}

Expand Down Expand Up @@ -158,23 +155,36 @@ class GCDTester extends AnyFlatSpec with Matchers with LazyLogging {

val cycle = tester.cycleCount

logger.info(
f"processed $cycle cycles $elapsedSeconds%.6f seconds ${cycle.toDouble / (1000000.0 * elapsedSeconds)}%5.3f MHz"
)
println(f"$elapsedSeconds%.6f seconds")
}

}

private val FastConf = true // less benchmarking, more testing

it should "run with InterpretedTester at Int size 16" in {
sizableTest(16)
sizableTest(16, from = 2, upTo = 100, showTime = false)
if (!FastConf) {
sizableTest(16, from = 2, upTo = 500, showTime = true)
}
}

it should "run with InterpretedTester at Int size 44" in {
sizableTest(44)
sizableTest(44, from = 2, upTo = 100, showTime = false)
if (!FastConf) {
sizableTest(44, from = 2, upTo = 500, showTime = true)
}
}

it should "run with InterpretedTester at size 64" in {
sizableTest(64, from = 2, upTo = 100, showTime = false)
if (!FastConf) {
sizableTest(64, from = 2, upTo = 500, showTime = true)
}
}

it should "run with InterpretedTester at size 68" in {
sizableTest(68)
sizableTest(68, from = 10, upTo = 100, showTime = false)
}

it should "run a lot of values" in {
Expand Down

0 comments on commit 2aaeba2

Please sign in to comment.