Benchmark text flow

This commit is contained in:
Sasha Koshka 2024-09-19 21:05:18 -04:00
parent 90b2e49664
commit e38cac8e3b

38
flow_test.go Normal file
View File

@ -0,0 +1,38 @@
package typeset
import "testing"
import "golang.org/x/image/math/fixed"
import "golang.org/x/image/font/basicfont"
func BenchmarkFlowLipsumLeftTop (benchmark *testing.B) {
benchmarkFlow(benchmark, false, AlignStart, AlignStart)
}
func BenchmarkFlowLipsumWrapLeftTop (benchmark *testing.B) {
benchmarkFlow(benchmark, true, AlignStart, AlignStart)
}
func BenchmarkFlowLipsumCenterTop (benchmark *testing.B) {
benchmarkFlow(benchmark, false, AlignMiddle, AlignStart)
}
func BenchmarkFlowLipsumWrapCenterTop (benchmark *testing.B) {
benchmarkFlow(benchmark, true, AlignMiddle, AlignStart)
}
func BenchmarkFlowLipsumWrapJustifyTop (benchmark *testing.B) {
benchmarkFlow(benchmark, true, AlignEven, AlignStart)
}
func benchmarkFlow (benchmark *testing.B, wrap bool, xAlign, yAlign Align) {
_, tokens := parseString(lipsumLt)
benchmark.ReportAllocs()
benchmark.ResetTimer()
for i := 0; i < benchmark.N; i ++ {
reflow (
tokens,
basicfont.Face7x13,
fixed.P(256, 256),
wrap, xAlign, yAlign)
}
}