From 3665351e1222a9e53ccf43da5acefc99ace0f164 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Fri, 9 Aug 2024 15:19:48 -0700 Subject: [PATCH] Scala benchmark: adjust interface code to match Rust --- lang-trials/scala-benchmark/main.css | 1 + .../src/main/scala/CircularLawApp.scala | 20 +++++++++---------- lang-trials/scala/main.css | 5 ----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lang-trials/scala-benchmark/main.css b/lang-trials/scala-benchmark/main.css index a89c3bc..f79e62c 100644 --- a/lang-trials/scala-benchmark/main.css +++ b/lang-trials/scala-benchmark/main.css @@ -15,6 +15,7 @@ canvas { float: left; background-color: #020202; border-radius: 10px; + margin-top: 5px; } input { diff --git a/lang-trials/scala-benchmark/src/main/scala/CircularLawApp.scala b/lang-trials/scala-benchmark/src/main/scala/CircularLawApp.scala index 2f74cd3..950e661 100644 --- a/lang-trials/scala-benchmark/src/main/scala/CircularLawApp.scala +++ b/lang-trials/scala-benchmark/src/main/scala/CircularLawApp.scala @@ -10,10 +10,10 @@ object CircularLawApp: val canvas = canvasTag(widthAttr := 600, heightAttr := 600) val ctx = canvas.ref.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D] - val (eigvalSeries, runTimeReport) = randomEigvalSeries[60]() - val timeVar = Var("0") + val (eigvalSeries, runTimeReport) = randEigvalSeries[60]() + val timeStepState = Var("0") - def draw(timeStr: String): Unit = + def draw(timeStep: String): Unit = // center and normalize the coordinate system val width = canvas.ref.width val height = canvas.ref.height @@ -27,7 +27,7 @@ object CircularLawApp: val res = width / (2*rDisp) // draw the eigenvalues - val eigvals = eigvalSeries(timeStr.toInt) + val eigvals = eigvalSeries(timeStep.toInt) for n <- 0 to eigvals(0).length-1 do ctx.beginPath() ctx.arc( @@ -58,7 +58,7 @@ object CircularLawApp: eigen.imaginaryEigenvalues.asInstanceOf[NArray[Double]] ) - def randomEigvalSeries[N <: Int]()(using ValueOf[N]): (List[(NArray[Double], NArray[Double])], String) = + def randEigvalSeries[N <: Int]()(using ValueOf[N]): (List[(NArray[Double], NArray[Double])], String) = val timeRes = 100 val dim: Int = valueOf[N] val startTime = System.currentTimeMillis() @@ -66,8 +66,7 @@ object CircularLawApp: NArray.tabulate(dim*dim)(k => (math.E*k*k) % 2 - 1) ).times(math.sqrt(3d / dim)) val series = List.tabulate(timeRes)(t => eigvalsRotated(A, t.toDouble / timeRes)) - val endTime = System.currentTimeMillis() - val runTime = endTime - startTime + val runTime = System.currentTimeMillis() - startTime (series, runTime.toString() + " ms") def main(args: Array[String]): Unit = @@ -79,13 +78,12 @@ object CircularLawApp: canvas, input( typ := "range", - minAttr := "0", maxAttr := (eigvalSeries.length-1).toString, controlled( - value <-- timeVar.signal, - onInput.mapToValue --> timeVar.writer + value <-- timeStepState.signal, + onInput.mapToValue --> timeStepState.writer ), - timeVar.signal --> draw + timeStepState.signal --> draw ) ) renderOnDomContentLoaded(document.body, app) diff --git a/lang-trials/scala/main.css b/lang-trials/scala/main.css index ea89d47..3aedb99 100644 --- a/lang-trials/scala/main.css +++ b/lang-trials/scala/main.css @@ -38,11 +38,6 @@ input.point-3 { text-align: center; } -#result-display { - margin-top: 10px; - font-weight: bold; -} - canvas { float: left; background-color: #020202;