Skip to content

Commit

Permalink
Rename benchmarks and add City LookupNetwork bench
Browse files Browse the repository at this point in the history
Previously, we were overemphasizing the benchmarks for unmarshaling into
an interface{}, even though that is a less common use case.
  • Loading branch information
oschwald committed Sep 8, 2019
1 parent 4d055ba commit eb12d4a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions reader_test.go
Expand Up @@ -661,7 +661,7 @@ func checkIpv6(t *testing.T, reader *Reader) {
}
}

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

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

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

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

func BenchmarkCityLookupNetwork(b *testing.B) {
db, err := Open("GeoLite2-City.mmdb")
require.NoError(b, err)

r := rand.New(rand.NewSource(time.Now().UnixNano()))
var result fullCity

ip := make(net.IP, 4)
for i := 0; i < b.N; i++ {
randomIPv4Address(r, ip)
_, _, err = db.LookupNetwork(ip, &result)
if err != nil {
b.Error(err)
}
}
assert.NoError(b, db.Close(), "error on close")
}

func BenchmarkCountryCode(b *testing.B) {
db, err := Open("GeoLite2-City.mmdb")
require.NoError(b, err)
Expand Down

0 comments on commit eb12d4a

Please sign in to comment.