@@ -1091,3 +1091,70 @@ func FuzzParseRFC3339(f *testing.F) {
10911091 }
10921092 })
10931093}
1094+
1095+ func TestAppendIntWidth (t * testing.T ) {
1096+ values := []int {0 , - 1 , 1 , 10 , - 10 , 99 , - 99 }
1097+ for _ , v := range values {
1098+ exp := AppendInt (nil , v , 2 )
1099+ got := AppendIntWidth2 (nil , v )
1100+ if ! bytes .Equal (got , exp ) {
1101+ t .Errorf ("AppendIntWidth2(%d) = %s, want %s" , v , got , exp )
1102+ }
1103+ }
1104+
1105+ got := AppendIntWidth2 (nil , 199 )
1106+ if ! bytes .Equal (got , []byte ("99" )) {
1107+ t .Errorf ("AppendIntWidth2(199) = %s, want %s" , got , []byte ("99" ))
1108+ }
1109+
1110+ values = append (values , 9999 , - 9999 , 10001 )
1111+ for _ , v := range values {
1112+ exp := AppendInt (nil , v , 4 )
1113+ got := AppendIntWidth4 (nil , v )
1114+ if ! bytes .Equal (got , exp ) {
1115+ t .Errorf ("AppendIntWidth4(%d) = %s, want %s" , v , got , exp )
1116+ }
1117+ }
1118+ }
1119+
1120+ func BenchmarkAppendIntWidth2 (b * testing.B ) {
1121+ b .Run ("name=AppendInt" , func (b * testing.B ) {
1122+ var buf = make ([]byte , 0 , 8 )
1123+ b .ResetTimer ()
1124+ for i := 0 ; i < b .N ; i ++ {
1125+ buf = AppendInt (buf [:0 ], 36 , 2 )
1126+ }
1127+ })
1128+ b .Run ("name=AppendIntWidth2" , func (b * testing.B ) {
1129+ var buf = make ([]byte , 0 , 8 )
1130+ b .ResetTimer ()
1131+ for i := 0 ; i < b .N ; i ++ {
1132+ buf = AppendIntWidth2 (buf [:0 ], 36 )
1133+ }
1134+ })
1135+ }
1136+
1137+ func BenchmarkAppendIntWidth4 (b * testing.B ) {
1138+ b .Run ("name=AppendInt" , func (b * testing.B ) {
1139+ var buf = make ([]byte , 0 , 8 )
1140+ b .ResetTimer ()
1141+ for i := 0 ; i < b .N ; i ++ {
1142+ buf = AppendInt (buf [:0 ], 360 , 4 )
1143+ }
1144+ })
1145+ b .Run ("name=AppendIntWidth4" , func (b * testing.B ) {
1146+ var buf = make ([]byte , 0 , 8 )
1147+ b .ResetTimer ()
1148+ for i := 0 ; i < b .N ; i ++ {
1149+ buf = AppendIntWidth4 (buf [:0 ], 360 )
1150+ }
1151+ })
1152+ }
1153+
1154+ func BenchmarkTimeFormatRFC3339 (b * testing.B ) {
1155+ tm := Now ()
1156+ buf := make ([]byte , 0 , 64 )
1157+ for i := 0 ; i < b .N ; i ++ {
1158+ buf = tm .AppendFormat (buf [:0 ], RFC3339 )
1159+ }
1160+ }
0 commit comments