Skip to content

Commit

Permalink
add fastdns resolver benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 22, 2024
1 parent 585ec96 commit 90ab689
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,45 @@ func TestClientLookup(t *testing.T) {
}
}
}

func BenchmarkResolverPureGo(b *testing.B) {
resolver := net.Resolver{PreferGo: true}

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
resolver.LookupNetIP(context.Background(), "ip4", "www.google.com")
}
})
}

func BenchmarkResolverCGO(b *testing.B) {
resolver := net.Resolver{PreferGo: false}

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
resolver.LookupNetIP(context.Background(), "ip4", "www.google.com")
}
})
}

func BenchmarkResolverFastdns(b *testing.B) {
resolver := Client{
Addr: "1.1.1.1:53",
Dialer: &UDPDialer{
Addr: func() (u *net.UDPAddr) { u, _ = net.ResolveUDPAddr("udp", "1.1.1.1:53"); return }(),
MaxConns: 1000,
},
}

b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
resolver.LookupNetIP(context.Background(), "ip4", "www.google.com")
}
})
}

0 comments on commit 90ab689

Please sign in to comment.