Skip to content

Commit

Permalink
visual-effects-ny benchmark: remove dependencies on time and random. …
Browse files Browse the repository at this point in the history
…Introduce number of iterations (#3218)
  • Loading branch information
pjBooms authored Jun 1, 2023
1 parent 0319db1 commit 8a15fbe
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package org.jetbrains.compose.demo.visuals.platform

actual fun nanoTime(): Long = System.nanoTime()
import kotlin.system.exitProcess

actual fun nanoTime(): Long = System.nanoTime()

actual fun measureTime() = nanoTime()

actual fun exit(): Unit = exitProcess(0)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import org.jetbrains.compose.demo.visuals.platform.exit
import org.jetbrains.compose.demo.visuals.platform.measureTime
import org.jetbrains.compose.demo.visuals.platform.nanoTime
import kotlin.math.*
import kotlin.random.Random
Expand All @@ -39,7 +42,9 @@ data class SnowFlake(

data class Star(val x: Dp, val y: Dp, val color: Color, val size: Dp)

fun random(): Float = Random.nextFloat()
val random = Random(123)

fun random(): Float = random.nextFloat()

class DoubleRocket(val particle: Particle) {
private val STATE_ROCKET = 0
Expand All @@ -66,12 +71,20 @@ class DoubleRocket(val particle: Particle) {
}
}

var numOfIterations = 1

private fun reset() {
state = STATE_ROCKET
particle.x = 0.0
particle.y = 1000.0
particle.vx = 2.1
particle.vy = -12.5
numOfIterations -=1
if (numOfIterations == 0) {
println((measureTime() - measureTime)/1000000)
exit()
}

}

private fun explode(time: Long) {
Expand Down Expand Up @@ -222,8 +235,11 @@ fun prepareStarsAndSnowFlakes(stars: SnapshotStateList<Star>, snowFlakes: Snapsh
}
}

var measureTime: Long = 0

@Composable
fun NYContent() {
measureTime = measureTime()
var time by remember { mutableStateOf(nanoTime()) }
var startTime = remember { nanoTime() }
var prevTime by remember { mutableStateOf(nanoTime()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package org.jetbrains.compose.demo.visuals.platform

expect fun nanoTime(): Long
expect fun nanoTime(): Long

expect fun measureTime(): Long
expect fun exit(): Unit
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package org.jetbrains.compose.demo.visuals.platform

actual fun nanoTime(): Long = System.nanoTime()
import kotlin.system.exitProcess

actual fun nanoTime(): Long = 0//System.nanoTime()

actual fun measureTime() = System.nanoTime()
actual fun exit(): Unit = exitProcess(0)
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package org.jetbrains.compose.demo.visuals.platform

actual fun nanoTime(): Long = kotlin.system.getTimeNanos()
import kotlin.system.exitProcess

actual fun nanoTime(): Long = kotlin.system.getTimeNanos()

actual fun measureTime() = nanoTime()
actual fun exit(): Unit = exitProcess(0)
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package org.jetbrains.compose.demo.visuals.platform

actual fun nanoTime(): Long = kotlin.system.getTimeNanos()
import kotlin.system.exitProcess

actual fun nanoTime(): Long = 0;//kotlin.system.getTimeNanos()

actual fun measureTime() = kotlin.system.getTimeNanos()
actual fun exit(): Unit = exitProcess(0)

0 comments on commit 8a15fbe

Please sign in to comment.