Skip to content

Commit

Permalink
validate 'meals eaten' in the philosophers benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: BohdanQQ <40754203+BohdanQQ@users.noreply.github.com>

Validate 'meals eaten' in the philosophers benchmark
  • Loading branch information
BohdanQQ authored and lbulej committed Jun 7, 2024
1 parent 04c7056 commit 85460d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.renaissance.scala.stm

import scala.collection.JavaConverters._
import org.renaissance.Benchmark
import org.renaissance.Benchmark._
import org.renaissance.BenchmarkContext
Expand Down Expand Up @@ -33,17 +34,21 @@ final class Philosophers extends Benchmark {
*/
private var mealCountParam: Int = _

private var expectedHash: String = _

override def setUpBeforeAll(c: BenchmarkContext) = {
threadCountParam = c.parameter("thread_count").toPositiveInteger
mealCountParam = c.parameter("meal_count").toPositiveInteger
val expectedOutput = Array.fill(threadCountParam)(mealCountParam).toSeq.asJava;
expectedHash = Validators.computeHash(expectedOutput);
}

override def run(c: BenchmarkContext): BenchmarkResult = {
// TODO: Return something useful, not elapsed time
RealityShowPhilosophers.run(mealCountParam, threadCountParam)
val mealsEaten = RealityShowPhilosophers.run(mealCountParam, threadCountParam)

// TODO: add proper validation
Validators.dummy()
() => {
Validators.hashing(expectedHash, mealsEaten.toSeq.asJava).validate()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object RealityShowPhilosophers {
}
}

def time(philosopherCount: Int, meals: Int): Long = {
def eatenMeals(philosopherCount: Int, meals: Int): Array[Int] = {
val names = for (i <- 0 until philosopherCount) yield {
s"philosopher-$i"
}
Expand All @@ -96,16 +96,18 @@ object RealityShowPhilosophers {
new PhilosopherThread(names(i), meals, forks(i), forks((i + 1) % forks.length))
}
val camera = new CameraThread(1000 / 60, forks, pthreads)
val start = System.currentTimeMillis
camera.start()
for (t <- pthreads) t.start()
for (t <- pthreads) t.join()
val elapsed = System.currentTimeMillis - start
camera.join()
elapsed
atomic { implicit txn =>
pthreads.map { p =>
p.mealsEaten.get(txn)
}
}
}

def run(meals: Int, philosopherCount: Int) = {
time(philosopherCount, meals)
eatenMeals(philosopherCount, meals)
}
}

0 comments on commit 85460d4

Please sign in to comment.