| 471 | } |
| 472 | |
| 473 | func BenchmarkIPList_Sort(b *testing.B) { |
| 474 | var list = iplibrary.NewIPList() |
| 475 | for i := 0; i < 1_000_000; i++ { |
| 476 | var item = &iplibrary.IPItem{ |
| 477 | Id: uint64(i), |
| 478 | IPFrom: iputils.ToBytes(strconv.Itoa(rands.Int(0, 255)) + "." + strconv.Itoa(rands.Int(0, 255)) + ".0.1"), |
| 479 | ExpiredAt: time.Now().Unix() + 60, |
| 480 | } |
| 481 | |
| 482 | if i%100 == 0 { |
| 483 | item.IPTo = iputils.ToBytes(strconv.Itoa(rands.Int(0, 255)) + "." + strconv.Itoa(rands.Int(0, 255)) + ".0.1") |
| 484 | } |
| 485 | |
| 486 | list.AddDelay(item) |
| 487 | } |
| 488 | |
| 489 | b.ResetTimer() |
| 490 | b.RunParallel(func(pb *testing.PB) { |
| 491 | for pb.Next() { |
| 492 | list.Sort() |
| 493 | } |
| 494 | }) |
| 495 | } |