@@ -259,77 +259,14 @@ func TestSetAliasesInvalidValue(t *testing.T) {
259259 }
260260}
261261
262- //
263- // Benchmarks
264- // cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
265- //
266- /*
267- //
268- // BenchmarkSprintf
269- // BenchmarkSprintf-16 500000 114.7 ns/op 8 B/op 1 allocs/op
270- //
271- func BenchmarkSprintf(b *testing.B) {
272- for n := 0; n < b.N; n++ {
273- _ = fmt.Sprintf("\033[%d;%dm", 8+60, 7)
274- }
275- }
276-
277- //
278- // BenchmarkAtoI
279- // BenchmarkAtoI-16 500000 34.44 ns/op 0 B/op 0 allocs/op
280- //
281- func BenchmarkAtoI(b *testing.B) {
282- for n := 0; n < b.N; n++ {
283- _ = "\033[" + strconv.Itoa(8+60) + ";" + strconv.Itoa(7) + "m"
284- }
285- }
286-
287- //
288- // BenchmarkConcat
289- // BenchmarkConcat-16 500000 168857 ns/op 1403048 B/op 2 allocs/op
290- //
291-
292- func BenchmarkConcat(b *testing.B) {
293- var sConcat string = ""
294- for n := 0; n < b.N; n++ {
295- sConcat += strconv.Itoa(n)
296- }
297- }
298-
299- //
300- // BenchmarkStringBuilder
301- // BenchmarkStringBuilder-16 500000 38.46 ns/op 41 B/op 0 allocs/op
302- //
303- func BenchmarkStringBuilder(b *testing.B) {
304- var sBuilder strings.Builder
305- for n := 0; n < b.N; n++ {
306- sBuilder.WriteString(strconv.Itoa(n))
307- }
308- }
309-
310- // BenchmarkParseColorString
311- // BenchmarkParseColorString-16 617618 1665 ns/op 808 B/op 16 allocs/op
312- func BenchmarkParseColorString(b *testing.B) {
313- for n := 0; n < b.N; n++ {
314- Parse("This is a prefix <ansi fg=blue bg=red>This is color</ansi> This is a suffix")
315- }
316- }
317-
318- // BenchmarkParseColorInt
319- // BenchmarkParseColorInt-16 880810 1393 ns/op 712 B/op 14 allocs/op
320- func BenchmarkParseColorInt(b *testing.B) {
321- for n := 0; n < b.N; n++ {
322- Parse("This is a prefix <ansi fg='9' bg='2'>This is color</ansi> This is a suffix")
323- }
324- }
325- */
326- // Name # Run Avg Runtime Bytes Allocated # of Allocat
327- // BenchmarkParseStreaming-16 34398 32720 ns/op 14958 B/op 297 allocs/op
262+ // cpu: Apple M3 Max
263+ // Name # Run Avg Runtime Bytes Allocated # of Allocat
264+ // BenchmarkParseStreaming-14 39277 29422 ns/op 27360 B/op 491 allocs/o
328265func BenchmarkParseStreaming (b * testing.B ) {
329266
330267 testStr := "This is text"
331- for i := 0 ; i < 20 ; i ++ {
332- testStr = "<ansi fg=black bg=\" white\" >" + testStr + "</ansi>"
268+ for i := 0 ; i < 5 ; i ++ { // heavily nested tags
269+ testStr = testStr + "<ansi fg=black bg=\" white\" >" + testStr + "</ansi>"
333270 }
334271
335272 reader := strings .NewReader (testStr )
@@ -343,14 +280,30 @@ func BenchmarkParseStreaming(b *testing.B) {
343280 }
344281}
345282
346- // BenchmarkParseNew-16 33194 35641 ns/op 23330 B/op 304 allocs/op
283+ // cpu: Apple M3 Max
284+ // Name # Run Avg Runtime Bytes Allocated # of Allocat
285+ // BenchmarkParse-14 37892 30006 ns/op 33892 B/op 497 allocs/op
347286func BenchmarkParse (b * testing.B ) {
348287
349288 testStr := "This is text"
350- for i := 0 ; i < 20 ; i ++ {
351- testStr = "<ansi fg=black bg=\" white\" >" + testStr + "</ansi>"
289+ for i := 0 ; i < 5 ; i ++ { // heavily nested tags
290+ testStr = testStr + "<ansi fg=black bg=\" white\" >" + testStr + "</ansi>"
352291 }
353292 for n := 0 ; n < b .N ; n ++ {
354293 Parse (testStr )
355294 }
356295}
296+
297+ // cpu: Apple M3 Max
298+ // Name # Run Avg Runtime Bytes Allocated # of Allocat
299+ // BenchmarkParseHTML-14 40748 28125 ns/op 32295 B/op 455 allocs/op
300+ func BenchmarkParseHTML (b * testing.B ) {
301+
302+ testStr := "This is text"
303+ for i := 0 ; i < 5 ; i ++ { // heavily nested tags
304+ testStr = testStr + "<ansi fg=black bg=\" white\" >" + testStr + "</ansi>"
305+ }
306+ for n := 0 ; n < b .N ; n ++ {
307+ Parse (testStr , HTML )
308+ }
309+ }
0 commit comments