bedrocktool/handlers/worlds/chunk_test.go

54 lines
1.1 KiB
Go
Raw Normal View History

2023-04-04 00:44:13 +00:00
package worlds_test
import (
2022-09-04 23:40:55 +00:00
"image/png"
"os"
2023-03-30 11:48:03 +00:00
"runtime/pprof"
"testing"
2023-04-04 00:44:13 +00:00
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world/chunk"
)
2022-09-04 23:40:55 +00:00
func Test(t *testing.T) {
data, _ := os.ReadFile("chunk.bin")
ch, _, _ := chunk.NetworkDecode(33, data, 6, cube.Range{0, 255}, true, false)
2023-04-04 00:44:13 +00:00
i := utils.Chunk2Img(ch, true)
2022-09-04 23:40:55 +00:00
f, _ := os.Create("chunk.png")
png.Encode(f, i)
f.Close()
}
func Benchmark_chunk_decode(b *testing.B) {
data, _ := os.ReadFile("chunk.bin")
2023-03-30 11:48:03 +00:00
cf, _ := os.Create("cpu.pprof")
err := pprof.StartCPUProfile(cf)
if err != nil {
b.Error(err)
}
for i := 0; i < b.N; i++ {
_, _, err := chunk.NetworkDecode(33, data, 6, cube.Range{0, 255}, true, false)
if err != nil {
b.Error(err)
}
}
2023-03-30 11:48:03 +00:00
pprof.StopCPUProfile()
}
func Benchmark_render_chunk(b *testing.B) {
data, _ := os.ReadFile("chunk.bin")
ch, _, _ := chunk.NetworkDecode(33, data, 6, cube.Range{0, 255}, true, false)
2023-03-30 11:48:03 +00:00
cf, _ := os.Create("cpu.pprof")
err := pprof.StartCPUProfile(cf)
if err != nil {
b.Error(err)
}
for i := 0; i < b.N; i++ {
2023-04-04 00:44:13 +00:00
utils.Chunk2Img(ch, true)
}
2023-03-30 11:48:03 +00:00
pprof.StopCPUProfile()
}