From e38cac8e3beeaaf41c79c9373182acf60ea304f0 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 19 Sep 2024 21:05:18 -0400 Subject: [PATCH] Benchmark text flow --- flow_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 flow_test.go diff --git a/flow_test.go b/flow_test.go new file mode 100644 index 0000000..3cfbd0a --- /dev/null +++ b/flow_test.go @@ -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) + } +}