@@ -697,6 +697,74 @@ func BenchmarkLookupNetwork(b *testing.B) {
697697 assert .NoError (b , db .Close (), "error on close" )
698698}
699699
700+ type fullCity struct {
701+ City struct {
702+ GeoNameID uint `maxminddb:"geoname_id"`
703+ Names map [string ]string `maxminddb:"names"`
704+ } `maxminddb:"city"`
705+ Continent struct {
706+ Code string `maxminddb:"code"`
707+ GeoNameID uint `maxminddb:"geoname_id"`
708+ Names map [string ]string `maxminddb:"names"`
709+ } `maxminddb:"continent"`
710+ Country struct {
711+ GeoNameID uint `maxminddb:"geoname_id"`
712+ IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
713+ IsoCode string `maxminddb:"iso_code"`
714+ Names map [string ]string `maxminddb:"names"`
715+ } `maxminddb:"country"`
716+ Location struct {
717+ AccuracyRadius uint16 `maxminddb:"accuracy_radius"`
718+ Latitude float64 `maxminddb:"latitude"`
719+ Longitude float64 `maxminddb:"longitude"`
720+ MetroCode uint `maxminddb:"metro_code"`
721+ TimeZone string `maxminddb:"time_zone"`
722+ } `maxminddb:"location"`
723+ Postal struct {
724+ Code string `maxminddb:"code"`
725+ } `maxminddb:"postal"`
726+ RegisteredCountry struct {
727+ GeoNameID uint `maxminddb:"geoname_id"`
728+ IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
729+ IsoCode string `maxminddb:"iso_code"`
730+ Names map [string ]string `maxminddb:"names"`
731+ } `maxminddb:"registered_country"`
732+ RepresentedCountry struct {
733+ GeoNameID uint `maxminddb:"geoname_id"`
734+ IsInEuropeanUnion bool `maxminddb:"is_in_european_union"`
735+ IsoCode string `maxminddb:"iso_code"`
736+ Names map [string ]string `maxminddb:"names"`
737+ Type string `maxminddb:"type"`
738+ } `maxminddb:"represented_country"`
739+ Subdivisions []struct {
740+ GeoNameID uint `maxminddb:"geoname_id"`
741+ IsoCode string `maxminddb:"iso_code"`
742+ Names map [string ]string `maxminddb:"names"`
743+ } `maxminddb:"subdivisions"`
744+ Traits struct {
745+ IsAnonymousProxy bool `maxminddb:"is_anonymous_proxy"`
746+ IsSatelliteProvider bool `maxminddb:"is_satellite_provider"`
747+ } `maxminddb:"traits"`
748+ }
749+
750+ func BenchmarkCityLookup (b * testing.B ) {
751+ db , err := Open ("GeoLite2-City.mmdb" )
752+ require .NoError (b , err )
753+
754+ r := rand .New (rand .NewSource (time .Now ().UnixNano ()))
755+ var result fullCity
756+
757+ ip := make (net.IP , 4 )
758+ for i := 0 ; i < b .N ; i ++ {
759+ randomIPv4Address (r , ip )
760+ err = db .Lookup (ip , & result )
761+ if err != nil {
762+ b .Error (err )
763+ }
764+ }
765+ assert .NoError (b , db .Close (), "error on close" )
766+ }
767+
700768func BenchmarkCountryCode (b * testing.B ) {
701769 db , err := Open ("GeoLite2-City.mmdb" )
702770 require .NoError (b , err )
0 commit comments