Scala benchmark: adjust interface code to match Rust
This commit is contained in:
parent
14fb6d01f0
commit
3665351e12
@ -15,6 +15,7 @@ canvas {
|
|||||||
float: left;
|
float: left;
|
||||||
background-color: #020202;
|
background-color: #020202;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
@ -10,10 +10,10 @@ object CircularLawApp:
|
|||||||
val canvas = canvasTag(widthAttr := 600, heightAttr := 600)
|
val canvas = canvasTag(widthAttr := 600, heightAttr := 600)
|
||||||
val ctx = canvas.ref.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
|
val ctx = canvas.ref.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
|
||||||
|
|
||||||
val (eigvalSeries, runTimeReport) = randomEigvalSeries[60]()
|
val (eigvalSeries, runTimeReport) = randEigvalSeries[60]()
|
||||||
val timeVar = Var("0")
|
val timeStepState = Var("0")
|
||||||
|
|
||||||
def draw(timeStr: String): Unit =
|
def draw(timeStep: String): Unit =
|
||||||
// center and normalize the coordinate system
|
// center and normalize the coordinate system
|
||||||
val width = canvas.ref.width
|
val width = canvas.ref.width
|
||||||
val height = canvas.ref.height
|
val height = canvas.ref.height
|
||||||
@ -27,7 +27,7 @@ object CircularLawApp:
|
|||||||
val res = width / (2*rDisp)
|
val res = width / (2*rDisp)
|
||||||
|
|
||||||
// draw the eigenvalues
|
// draw the eigenvalues
|
||||||
val eigvals = eigvalSeries(timeStr.toInt)
|
val eigvals = eigvalSeries(timeStep.toInt)
|
||||||
for n <- 0 to eigvals(0).length-1 do
|
for n <- 0 to eigvals(0).length-1 do
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.arc(
|
ctx.arc(
|
||||||
@ -58,7 +58,7 @@ object CircularLawApp:
|
|||||||
eigen.imaginaryEigenvalues.asInstanceOf[NArray[Double]]
|
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 timeRes = 100
|
||||||
val dim: Int = valueOf[N]
|
val dim: Int = valueOf[N]
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
@ -66,8 +66,7 @@ object CircularLawApp:
|
|||||||
NArray.tabulate(dim*dim)(k => (math.E*k*k) % 2 - 1)
|
NArray.tabulate(dim*dim)(k => (math.E*k*k) % 2 - 1)
|
||||||
).times(math.sqrt(3d / dim))
|
).times(math.sqrt(3d / dim))
|
||||||
val series = List.tabulate(timeRes)(t => eigvalsRotated(A, t.toDouble / timeRes))
|
val series = List.tabulate(timeRes)(t => eigvalsRotated(A, t.toDouble / timeRes))
|
||||||
val endTime = System.currentTimeMillis()
|
val runTime = System.currentTimeMillis() - startTime
|
||||||
val runTime = endTime - startTime
|
|
||||||
(series, runTime.toString() + " ms")
|
(series, runTime.toString() + " ms")
|
||||||
|
|
||||||
def main(args: Array[String]): Unit =
|
def main(args: Array[String]): Unit =
|
||||||
@ -79,13 +78,12 @@ object CircularLawApp:
|
|||||||
canvas,
|
canvas,
|
||||||
input(
|
input(
|
||||||
typ := "range",
|
typ := "range",
|
||||||
minAttr := "0",
|
|
||||||
maxAttr := (eigvalSeries.length-1).toString,
|
maxAttr := (eigvalSeries.length-1).toString,
|
||||||
controlled(
|
controlled(
|
||||||
value <-- timeVar.signal,
|
value <-- timeStepState.signal,
|
||||||
onInput.mapToValue --> timeVar.writer
|
onInput.mapToValue --> timeStepState.writer
|
||||||
),
|
),
|
||||||
timeVar.signal --> draw
|
timeStepState.signal --> draw
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
renderOnDomContentLoaded(document.body, app)
|
renderOnDomContentLoaded(document.body, app)
|
||||||
|
@ -38,11 +38,6 @@ input.point-3 {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#result-display {
|
|
||||||
margin-top: 10px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
float: left;
|
float: left;
|
||||||
background-color: #020202;
|
background-color: #020202;
|
||||||
|
Loading…
Reference in New Issue
Block a user