From aded8564ec4402e5fa8221253b21e8f89a984f87 Mon Sep 17 00:00:00 2001 From: BohdanQQ <40754203+BohdanQQ@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:07:03 +0200 Subject: [PATCH] validate 'meals eaten' in the philosophers benchmark Signed-off-by: BohdanQQ <40754203+BohdanQQ@users.noreply.github.com> Validate 'meals eaten' in the philosophers benchmark --- .../org/renaissance/scala/stm/Philosophers.scala | 13 +++++++++---- .../scala/stm/RealityShowPhilosophers.scala | 12 +++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/Philosophers.scala b/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/Philosophers.scala index aacb5e45..22478684 100644 --- a/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/Philosophers.scala +++ b/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/Philosophers.scala @@ -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 @@ -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() + } } } diff --git a/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/RealityShowPhilosophers.scala b/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/RealityShowPhilosophers.scala index eb2e95d6..7597510c 100644 --- a/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/RealityShowPhilosophers.scala +++ b/benchmarks/scala-stm/src/main/scala/org/renaissance/scala/stm/RealityShowPhilosophers.scala @@ -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" } @@ -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) } }