Initial commit: RegionIO Minecraft server core (26.1.2/protocol 775)
Vanilla-faithful overworld generator (final_density + multi-noise biomes), full connection lifecycle (status/login/configuration/play), chunk streaming, creative block editing, and the protocol/nbt/registry infrastructure.
This commit is contained in:
commit
a7bb9496ae
146 changed files with 217621 additions and 0 deletions
79
internal/world/bench_test.go
Normal file
79
internal/world/bench_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package world
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkGenerateFlat(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = GenerateFlat(int32(i), 0)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncode(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = GenerateFlat(int32(i), 0).Encode()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodeAndCompress(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
var buf bytes.Buffer
|
||||
for i := 0; i < b.N; i++ {
|
||||
body := GenerateFlat(int32(i), 0).Encode()
|
||||
buf.Reset()
|
||||
zw := zlib.NewWriter(&buf)
|
||||
zw.Write(body)
|
||||
zw.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// One join currently sends a (2*radius+1)^2 grid; benchmark that batch.
|
||||
func BenchmarkJoinChunkBatch(b *testing.B) {
|
||||
const radius = 4
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for cx := int32(-radius); cx <= radius; cx++ {
|
||||
for cz := int32(-radius); cz <= radius; cz++ {
|
||||
_ = GenerateFlat(cx, cz).Encode()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCacheWarmJoin(b *testing.B) {
|
||||
const radius = 4
|
||||
c := NewCache(256, GenerateFlat)
|
||||
// Warm the cache once (cold join).
|
||||
for cx := int32(-radius); cx <= radius; cx++ {
|
||||
for cz := int32(-radius); cz <= radius; cz++ {
|
||||
c.Frame(cx, cz)
|
||||
}
|
||||
}
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for cx := int32(-radius); cx <= radius; cx++ {
|
||||
for cz := int32(-radius); cz <= radius; cz++ {
|
||||
_ = c.Frame(cx, cz) // all hits
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCacheColdJoin(b *testing.B) {
|
||||
const radius = 4
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := NewCache(256, GenerateFlat) // fresh cache each iter = all misses
|
||||
for cx := int32(-radius); cx <= radius; cx++ {
|
||||
for cz := int32(-radius); cz <= radius; cz++ {
|
||||
_ = c.Frame(cx, cz)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue