| 225 | } |
| 226 | |
| 227 | func BenchmarkLogLineCopy(b *testing.B) { |
| 228 | b.Run("set=0", func(b *testing.B) { |
| 229 | ll := &baker.LogLine{FieldSeparator: baker.DefaultLogLineFieldSeparator} |
| 230 | buf := bytes.Repeat([]byte(`hello,world,,`), 200) |
| 231 | ll.Parse(buf, nil) |
| 232 | |
| 233 | b.ReportAllocs() |
| 234 | |
| 235 | var cpy baker.Record |
| 236 | for n := 0; n < b.N; n++ { |
| 237 | cpy = ll.Copy() |
| 238 | } |
| 239 | |
| 240 | if !bytes.Equal(ll.ToText(nil), cpy.ToText(nil)) { |
| 241 | b.Error("copy != original") |
| 242 | } |
| 243 | }) |
| 244 | |
| 245 | b.Run("set=1", func(b *testing.B) { |
| 246 | ll := &baker.LogLine{FieldSeparator: baker.DefaultLogLineFieldSeparator} |
| 247 | buf := bytes.Repeat([]byte(`hello,world,,`), 200) |
| 248 | ll.Parse(buf, nil) |
| 249 | ll.Set(0, []byte("foobar")) |
| 250 | |
| 251 | b.ReportAllocs() |
| 252 | |
| 253 | var cpy baker.Record |
| 254 | for n := 0; n < b.N; n++ { |
| 255 | cpy = ll.Copy() |
| 256 | } |
| 257 | |
| 258 | if !bytes.Equal(ll.ToText(nil), cpy.ToText(nil)) { |
| 259 | b.Error("copy != original") |
| 260 | } |
| 261 | }) |
| 262 | |
| 263 | b.Run("set=10", func(b *testing.B) { |
| 264 | ll := &baker.LogLine{FieldSeparator: baker.DefaultLogLineFieldSeparator} |
| 265 | buf := bytes.Repeat([]byte(`hello,world,,`), 200) |
| 266 | ll.Parse(buf, nil) |
| 267 | ll.Set(0, []byte("foobar")) |
| 268 | ll.Set(2, []byte("foobar")) |
| 269 | ll.Set(3, []byte("foobar")) |
| 270 | ll.Set(6, []byte("foobar")) |
| 271 | ll.Set(30, []byte("foobar")) |
| 272 | ll.Set(79, []byte("foobar")) |
| 273 | ll.Set(124, []byte("foobar")) |
| 274 | ll.Set(189, []byte("foobar")) |
| 275 | ll.Set(234, []byte("foobar")) |
| 276 | ll.Set(798, []byte("foobar")) |
| 277 | |
| 278 | b.ReportAllocs() |
| 279 | |
| 280 | var cpy baker.Record |
| 281 | for n := 0; n < b.N; n++ { |
| 282 | cpy = ll.Copy() |
| 283 | } |
| 284 | |