status_timing_test.go 760 B

123456789101112131415161718192021222324252627282930
  1. package fasthttp
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func BenchmarkStatusLine99(b *testing.B) {
  7. benchmarkStatusLine(b, 99, []byte("HTTP/1.1 99 Unknown Status Code\r\n"))
  8. }
  9. func BenchmarkStatusLine200(b *testing.B) {
  10. benchmarkStatusLine(b, 200, []byte("HTTP/1.1 200 OK\r\n"))
  11. }
  12. func BenchmarkStatusLine512(b *testing.B) {
  13. benchmarkStatusLine(b, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n"))
  14. }
  15. func benchmarkStatusLine(b *testing.B, statusCode int, expected []byte) {
  16. b.RunParallel(func(pb *testing.PB) {
  17. for pb.Next() {
  18. line := formatStatusLine(nil, strHTTP11, statusCode, s2b(StatusMessage(statusCode)))
  19. if !bytes.Equal(expected, line) {
  20. b.Fatalf("unexpected status line %s. Expecting %s", string(line), string(expected))
  21. }
  22. }
  23. })
  24. }