File: status_timing_test.go

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (29 lines) | stat: -rw-r--r-- 760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package fasthttp

import (
	"bytes"
	"testing"
)

func BenchmarkStatusLine99(b *testing.B) {
	benchmarkStatusLine(b, 99, []byte("HTTP/1.1 99 Unknown Status Code\r\n"))
}

func BenchmarkStatusLine200(b *testing.B) {
	benchmarkStatusLine(b, 200, []byte("HTTP/1.1 200 OK\r\n"))
}

func BenchmarkStatusLine512(b *testing.B) {
	benchmarkStatusLine(b, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n"))
}

func benchmarkStatusLine(b *testing.B, statusCode int, expected []byte) {
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			line := formatStatusLine(nil, strHTTP11, statusCode, s2b(StatusMessage(statusCode)))
			if !bytes.Equal(expected, line) {
				b.Fatalf("unexpected status line %q. Expecting %q", string(line), string(expected))
			}
		}
	})
}