| 413 | } |
| 414 | |
| 415 | func BenchmarkIPList_Add(b *testing.B) { |
| 416 | runtime.GOMAXPROCS(1) |
| 417 | |
| 418 | var list = iplibrary.NewIPList() |
| 419 | for i := 1; i < 200_000; i++ { |
| 420 | list.AddDelay(&iplibrary.IPItem{ |
| 421 | Id: uint64(i), |
| 422 | IPFrom: iputils.ToBytes(strconv.Itoa(rands.Int(0, 255)) + "." + strconv.Itoa(rands.Int(0, 255)) + ".0.1"), |
| 423 | IPTo: iputils.ToBytes(strconv.Itoa(rands.Int(0, 255)) + "." + strconv.Itoa(rands.Int(0, 255)) + ".0.1"), |
| 424 | ExpiredAt: time.Now().Unix() + 60, |
| 425 | }) |
| 426 | } |
| 427 | |
| 428 | list.Sort() |
| 429 | |
| 430 | b.Log(len(list.ItemsMap()), "ip") |
| 431 | |
| 432 | b.ResetTimer() |
| 433 | |
| 434 | for i := 0; i < b.N; i++ { |
| 435 | var ip = fmt.Sprintf("%d.%d.%d.%d", rand.Int()%255, rand.Int()%255, rand.Int()%255, rand.Int()%255) |
| 436 | list.Add(&iplibrary.IPItem{ |
| 437 | Type: "", |
| 438 | Id: uint64(i % 1_000_000), |
| 439 | IPFrom: iputils.ToBytes(ip), |
| 440 | IPTo: nil, |
| 441 | ExpiredAt: fasttime.Now().Unix() + 3600, |
| 442 | EventLevel: "", |
| 443 | }) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | func BenchmarkIPList_Contains(b *testing.B) { |
| 448 | runtime.GOMAXPROCS(1) |