Created
February 2, 2026 11:51
-
-
Save varfrog/dbfa04bf92d2ccf7f61630d7d691348d to your computer and use it in GitHub Desktop.
Collapse spaces - benchmark tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package collapse | |
| import ( | |
| "strings" | |
| "testing" | |
| ) | |
| var sink string // prevents compiler optimizations | |
| func benchmarkInput() string { | |
| return strings.Repeat("a b c d ", 200) | |
| } | |
| func BenchmarkCollapseContains(b *testing.B) { | |
| input := benchmarkInput() | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| sink = CollapseContains(input) | |
| } | |
| } | |
| func BenchmarkCollapseBuilder(b *testing.B) { | |
| input := benchmarkInput() | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| sink = CollapseBuilder(input) | |
| } | |
| } | |
| func BenchmarkCollapseFields(b *testing.B) { | |
| input := benchmarkInput() | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| sink = CollapseFields(input) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment