Skip to content

Commit eb12d4a

Browse files
committed
Rename benchmarks and add City LookupNetwork bench
Previously, we were overemphasizing the benchmarks for unmarshaling into an interface{}, even though that is a less common use case.
1 parent 4d055ba commit eb12d4a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

reader_test.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ func checkIpv6(t *testing.T, reader *Reader) {
661661
}
662662
}
663663

664-
func BenchmarkLookup(b *testing.B) {
664+
func BenchmarkInterfaceLookup(b *testing.B) {
665665
db, err := Open("GeoLite2-City.mmdb")
666666
require.NoError(b, err)
667667

@@ -679,7 +679,7 @@ func BenchmarkLookup(b *testing.B) {
679679
assert.NoError(b, db.Close(), "error on close")
680680
}
681681

682-
func BenchmarkLookupNetwork(b *testing.B) {
682+
func BenchmarkInterfaceLookupNetwork(b *testing.B) {
683683
db, err := Open("GeoLite2-City.mmdb")
684684
require.NoError(b, err)
685685

@@ -765,6 +765,24 @@ func BenchmarkCityLookup(b *testing.B) {
765765
assert.NoError(b, db.Close(), "error on close")
766766
}
767767

768+
func BenchmarkCityLookupNetwork(b *testing.B) {
769+
db, err := Open("GeoLite2-City.mmdb")
770+
require.NoError(b, err)
771+
772+
r := rand.New(rand.NewSource(time.Now().UnixNano()))
773+
var result fullCity
774+
775+
ip := make(net.IP, 4)
776+
for i := 0; i < b.N; i++ {
777+
randomIPv4Address(r, ip)
778+
_, _, err = db.LookupNetwork(ip, &result)
779+
if err != nil {
780+
b.Error(err)
781+
}
782+
}
783+
assert.NoError(b, db.Close(), "error on close")
784+
}
785+
768786
func BenchmarkCountryCode(b *testing.B) {
769787
db, err := Open("GeoLite2-City.mmdb")
770788
require.NoError(b, err)

0 commit comments

Comments
 (0)