Scala benchmark: adjust interface code to match Rust

This commit is contained in:
Aaron Fenyes 2024-08-09 15:19:48 -07:00
parent 14fb6d01f0
commit 3665351e12
3 changed files with 10 additions and 16 deletions

View File

@ -15,6 +15,7 @@ canvas {
float: left;
background-color: #020202;
border-radius: 10px;
margin-top: 5px;
}
input {

View File

@ -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)

View File

@ -38,11 +38,6 @@ input.point-3 {
text-align: center;
}
#result-display {
margin-top: 10px;
font-weight: bold;
}
canvas {
float: left;
background-color: #020202;