github.com/kamalshkeir/kencoding@v0.0.2-0.20230409043843-44b609a0475a/json/string_test.go (about) 1 package json 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func BenchmarkEscapeIndex4KB(b *testing.B) { 9 benchmarkEscapeIndex(b, strings.Repeat("!foobar!", 512), false) 10 } 11 12 func BenchmarkEscapeIndex4KBEscapeHTML(b *testing.B) { 13 benchmarkEscapeIndex(b, strings.Repeat("!foobar!", 512), true) 14 } 15 16 func BenchmarkEscapeIndex1(b *testing.B) { 17 benchmarkEscapeIndex(b, "1", false) 18 } 19 20 func BenchmarkEscapeIndex1EscapeHTML(b *testing.B) { 21 benchmarkEscapeIndex(b, "1", true) 22 } 23 24 func BenchmarkEscapeIndex7(b *testing.B) { 25 benchmarkEscapeIndex(b, "1234567", false) 26 } 27 28 func BenchmarkEscapeIndex7EscapeHTML(b *testing.B) { 29 benchmarkEscapeIndex(b, "1234567", true) 30 } 31 32 func benchmarkEscapeIndex(b *testing.B, s string, escapeHTML bool) { 33 b.ResetTimer() 34 for i := 0; i < b.N; i++ { 35 escapeIndex(s, escapeHTML) 36 } 37 b.SetBytes(int64(len(s))) 38 }