diff options
Diffstat (limited to 'libgo/go/net/ip_test.go')
-rw-r--r-- | libgo/go/net/ip_test.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libgo/go/net/ip_test.go b/libgo/go/net/ip_test.go index ad13388..a5fc5e6 100644 --- a/libgo/go/net/ip_test.go +++ b/libgo/go/net/ip_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !js + package net import ( @@ -129,7 +131,7 @@ func TestMarshalEmptyIP(t *testing.T) { } } -var ipStringTests = []struct { +var ipStringTests = []*struct { in IP // see RFC 791 and RFC 4291 str string // see RFC 791, RFC 4291 and RFC 5952 byt []byte @@ -252,9 +254,21 @@ var sink string func BenchmarkIPString(b *testing.B) { testHookUninstaller.Do(uninstallTestHooks) + b.Run("IPv4", func(b *testing.B) { + benchmarkIPString(b, IPv4len) + }) + + b.Run("IPv6", func(b *testing.B) { + benchmarkIPString(b, IPv6len) + }) +} + +func benchmarkIPString(b *testing.B, size int) { + b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { for _, tt := range ipStringTests { - if tt.in != nil { + if tt.in != nil && len(tt.in) == size { sink = tt.in.String() } } |