aboutsummaryrefslogtreecommitdiff
path: root/client_timing_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-26 17:04:27 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-26 17:04:27 +0200
commita3fd75d2379eebcbc4ec99f0044bee9236a25474 (patch)
tree811bfe6a31f7463ae55317fd1a2813e2089074e6 /client_timing_test.go
parentworkerpool: immediately switch to connection processing if GOMAXPROCS=1. This... (diff)
downloadfasthttp-a3fd75d2379eebcbc4ec99f0044bee9236a25474.tar.gz
fasthttp-a3fd75d2379eebcbc4ec99f0044bee9236a25474.tar.bz2
fasthttp-a3fd75d2379eebcbc4ec99f0044bee9236a25474.zip
Eliminated memory allocations from client's DoTimeout and GetTimeout
Diffstat (limited to 'client_timing_test.go')
-rw-r--r--client_timing_test.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/client_timing_test.go b/client_timing_test.go
index 3166600..ec8f5b8 100644
--- a/client_timing_test.go
+++ b/client_timing_test.go
@@ -69,7 +69,37 @@ func acquireFakeServerConn(s []byte) *fakeClientConn {
var fakeClientConnPool sync.Pool
-func BenchmarkClientGetFastServer(b *testing.B) {
+func BenchmarkClientGetTimeoutFastServer(b *testing.B) {
+ body := []byte("123456789099")
+ s := []byte(fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s", len(body), body))
+ c := &Client{
+ Dial: func(addr string) (net.Conn, error) {
+ return acquireFakeServerConn(s), nil
+ },
+ }
+
+ nn := uint32(0)
+ b.RunParallel(func(pb *testing.PB) {
+ url := fmt.Sprintf("http://foobar%d.com/aaa/bbb", atomic.AddUint32(&nn, 1))
+ var statusCode int
+ var bodyBuf []byte
+ var err error
+ for pb.Next() {
+ statusCode, bodyBuf, err = c.GetTimeout(bodyBuf[:0], url, time.Second)
+ if err != nil {
+ b.Fatalf("unexpected error: %s", err)
+ }
+ if statusCode != StatusOK {
+ b.Fatalf("unexpected status code: %d", statusCode)
+ }
+ if !bytes.Equal(bodyBuf, body) {
+ b.Fatalf("unexpected response body: %q. Expected %q", bodyBuf, body)
+ }
+ }
+ })
+}
+
+func BenchmarkClientDoFastServer(b *testing.B) {
body := []byte("012345678912")
s := []byte(fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s", len(body), body))
c := &Client{
@@ -97,7 +127,7 @@ func BenchmarkClientGetFastServer(b *testing.B) {
})
}
-func BenchmarkNetHTTPClientGetFastServer(b *testing.B) {
+func BenchmarkNetHTTPClientDoFastServer(b *testing.B) {
body := []byte("012345678912")
s := []byte(fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s", len(body), body))
c := &http.Client{