add light benchmarks

This commit is contained in:
Bixilon 2022-10-06 23:07:32 +02:00
parent 25d7e29b5b
commit 0a8e882714
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 48 additions and 0 deletions

View File

@ -373,6 +373,7 @@ class ChunkLight(private val chunk: Chunk) {
fun recalculateSkylight(sectionHeight: Int) {
val minY = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y
// TODO
}
}

View File

@ -13,11 +13,14 @@
package de.bixilon.minosoft.data.world.chunk.light
import de.bixilon.kutil.unit.UnitFormatter.formatNanos
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.createChunkWithNeighbours
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.createSolidBlock
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.createSolidLight
import de.bixilon.minosoft.data.world.chunk.ChunkTestingUtil.fillBottom
import de.bixilon.minosoft.util.benchmark.BenchmarkUtil
import org.junit.jupiter.api.Test
import kotlin.system.measureNanoTime
internal class LightBenchmark {
@ -38,4 +41,48 @@ internal class LightBenchmark {
chunk.light.recalculate()
}.println()
}
// same tests like https://github.com/PaperMC/Starlight
@Test
fun calculateSimplePlace() {
val chunk = createChunkWithNeighbours()
val solid = createSolidBlock().defaultState
val light = createSolidLight().defaultState
for (index in 0 until 256) {
chunk.getOrPut(0)!!.blocks.unsafeSet(index, solid)
}
for (index in 0 until 256) {
chunk.getOrPut(15)!!.blocks.unsafeSet(index or (0x0F shl 8), solid)
}
var totalPlace = 0L
var totalBreak = 0L
val benchmark = BenchmarkUtil.benchmark(50000) {
totalPlace += measureNanoTime { chunk.set(7, 1, 7, light) }
totalBreak += measureNanoTime { chunk.set(7, 1, 7, null) }
}
println("Placing light took ${totalPlace.formatNanos()}, avg=${(totalPlace / benchmark.runs).formatNanos()}, runs=${benchmark.runs}")
println("Breaking light took ${totalBreak.formatNanos()}, avg=${(totalBreak / benchmark.runs).formatNanos()}, runs=${benchmark.runs}")
}
@Test
fun calculateChangeAtY255() {
val chunk = createChunkWithNeighbours()
val solid = createSolidBlock().defaultState
for (index in 0 until 256) {
chunk.getOrPut(0)!!.blocks.unsafeSet(index, solid)
}
for (index in 0 until 256) {
chunk.getOrPut(15)!!.blocks.unsafeSet(index or (0x0F shl 8), solid)
}
var totalPlace = 0L
var totalBreak = 0L
val benchmark = BenchmarkUtil.benchmark(50000) {
totalBreak += measureNanoTime { chunk.set(7, 255, 7, null) }
totalPlace += measureNanoTime { chunk.set(7, 255, 7, solid) }
}
println("Placing block took ${totalPlace.formatNanos()}, avg=${(totalPlace / benchmark.runs).formatNanos()}, runs=${benchmark.runs}")
println("Breaking block took ${totalBreak.formatNanos()}, avg=${(totalBreak / benchmark.runs).formatNanos()}, runs=${benchmark.runs}")
}
}