]> Cypherpunks repositories - gostls13.git/commitdiff
net: add TCP over IPv6 benchmarks
authorMikio Hara <mikioh.mikioh@gmail.com>
Sun, 3 Mar 2013 02:25:49 +0000 (11:25 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sun, 3 Mar 2013 02:25:49 +0000 (11:25 +0900)
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7433044

src/pkg/net/tcp_test.go

index 1d54b3adcc759c2af45ad93997aaf515e127cb32..6c4485a94891ff4daa9b7fa585f35bfb76df1f12 100644 (file)
@@ -11,23 +11,51 @@ import (
        "time"
 )
 
-func BenchmarkTCPOneShot(b *testing.B) {
-       benchmarkTCP(b, false, false)
+func BenchmarkTCP4OneShot(b *testing.B) {
+       benchmarkTCP(b, false, false, "127.0.0.1:0")
 }
 
-func BenchmarkTCPOneShotTimeout(b *testing.B) {
-       benchmarkTCP(b, false, true)
+func BenchmarkTCP4OneShotTimeout(b *testing.B) {
+       benchmarkTCP(b, false, true, "127.0.0.1:0")
 }
 
-func BenchmarkTCPPersistent(b *testing.B) {
-       benchmarkTCP(b, true, false)
+func BenchmarkTCP4Persistent(b *testing.B) {
+       benchmarkTCP(b, true, false, "127.0.0.1:0")
 }
 
-func BenchmarkTCPPersistentTimeout(b *testing.B) {
-       benchmarkTCP(b, true, true)
+func BenchmarkTCP4PersistentTimeout(b *testing.B) {
+       benchmarkTCP(b, true, true, "127.0.0.1:0")
 }
 
-func benchmarkTCP(b *testing.B, persistent, timeout bool) {
+func BenchmarkTCP6OneShot(b *testing.B) {
+       if !supportsIPv6 {
+               b.Skip("ipv6 is not supported")
+       }
+       benchmarkTCP(b, false, false, "[::1]:0")
+}
+
+func BenchmarkTCP6OneShotTimeout(b *testing.B) {
+       if !supportsIPv6 {
+               b.Skip("ipv6 is not supported")
+       }
+       benchmarkTCP(b, false, true, "[::1]:0")
+}
+
+func BenchmarkTCP6Persistent(b *testing.B) {
+       if !supportsIPv6 {
+               b.Skip("ipv6 is not supported")
+       }
+       benchmarkTCP(b, true, false, "[::1]:0")
+}
+
+func BenchmarkTCP6PersistentTimeout(b *testing.B) {
+       if !supportsIPv6 {
+               b.Skip("ipv6 is not supported")
+       }
+       benchmarkTCP(b, true, true, "[::1]:0")
+}
+
+func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) {
        const msgLen = 512
        conns := b.N
        numConcurrent := runtime.GOMAXPROCS(-1) * 16
@@ -61,7 +89,7 @@ func benchmarkTCP(b *testing.B, persistent, timeout bool) {
                }
                return true
        }
-       ln, err := Listen("tcp", "127.0.0.1:0")
+       ln, err := Listen("tcp", laddr)
        if err != nil {
                b.Fatalf("Listen failed: %v", err)
        }