MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / BenchmarkIPList_Add

Function BenchmarkIPList_Add

internal/iplibrary/ip_list_test.go:415–445  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

413}
414
415func 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
447func BenchmarkIPList_Contains(b *testing.B) {
448 runtime.GOMAXPROCS(1)

Callers

nothing calls this directly

Calls 8

NewIPListFunction · 0.92
NowFunction · 0.92
AddDelayMethod · 0.80
UnixMethod · 0.80
SortMethod · 0.80
LogMethod · 0.80
AddMethod · 0.65
ItemsMapMethod · 0.45

Tested by

no test coverage detected