diff --git a/integrationtests/self/benchmark_test.go b/integrationtests/self/benchmark_test.go new file mode 100644 index 00000000..eaab654a --- /dev/null +++ b/integrationtests/self/benchmark_test.go @@ -0,0 +1,92 @@ +package self_test + +import ( + "context" + "fmt" + "net" + "testing" + + "github.com/quic-go/quic-go" +) + +func BenchmarkHandshake(b *testing.B) { + b.ReportAllocs() + + ln, err := quic.ListenAddr("localhost:0", tlsConfig, nil) + if err != nil { + b.Fatal(err) + } + defer ln.Close() + + connChan := make(chan quic.Connection, 1) + go func() { + for { + conn, err := ln.Accept(context.Background()) + if err != nil { + return + } + connChan <- conn + } + }() + + conn, err := net.ListenUDP("udp", nil) + if err != nil { + b.Fatal(err) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + c, err := quic.Dial(conn, ln.Addr(), "localhost", tlsClientConfig, nil) + if err != nil { + b.Fatal(err) + } + <-connChan + c.CloseWithError(0, "") + } +} + +func BenchmarkStreamChurn(b *testing.B) { + b.ReportAllocs() + + ln, err := quic.ListenAddr("localhost:0", tlsConfig, &quic.Config{MaxIncomingStreams: 1e10}) + if err != nil { + b.Fatal(err) + } + defer ln.Close() + + errChan := make(chan error, 1) + go func() { + conn, err := ln.Accept(context.Background()) + if err != nil { + errChan <- err + return + } + close(errChan) + for { + str, err := conn.AcceptStream(context.Background()) + if err != nil { + return + } + str.Close() + } + }() + + c, err := quic.DialAddr(fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port), tlsClientConfig, nil) + if err != nil { + b.Fatal(err) + } + if err := <-errChan; err != nil { + b.Fatal(err) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + str, err := c.OpenStreamSync(context.Background()) + if err != nil { + b.Fatal(err) + } + if err := str.Close(); err != nil { + b.Fatal(err) + } + } +} diff --git a/integrationtests/self/self_suite_test.go b/integrationtests/self/self_suite_test.go index 85955546..943b8753 100644 --- a/integrationtests/self/self_suite_test.go +++ b/integrationtests/self/self_suite_test.go @@ -106,10 +106,6 @@ var ( func init() { flag.StringVar(&logFileName, "logfile", "", "log file") flag.BoolVar(&enableQlog, "qlog", false, "enable qlog") -} - -var _ = BeforeSuite(func() { - mrand.Seed(GinkgoRandomSeed()) ca, caPrivateKey, err := generateCA() if err != nil { @@ -138,6 +134,10 @@ var _ = BeforeSuite(func() { RootCAs: root, NextProtos: []string{alpn}, } +} + +var _ = BeforeSuite(func() { + mrand.Seed(GinkgoRandomSeed()) if enableQlog { quicConfigTracer = qlog.NewTracer(func(p logging.Perspective, connectionID []byte) io.WriteCloser {