-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve statusLine and StatusMessage by using slice instead of map (#…
…855) * 🚀 improve statusLine and StatusMessage by using slice instead of map Co-authored-by: Fenny <fenny@gofiber.io> Co-authored-by: ReneWerner87 <rene@gofiber.io> * for cli stuff * make invalidStatusLine() just return the formatted line * for ci stuff Co-authored-by: Fenny <fenny@gofiber.io> Co-authored-by: ReneWerner87 <rene@gofiber.io>
- Loading branch information
1 parent
a7c7ef2
commit 2509c12
Showing
3 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fasthttp | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestStatusLine(t *testing.T) { | ||
t.Parallel() | ||
|
||
testStatusLine(t, -1, []byte("HTTP/1.1 -1 Unknown Status Code\r\n")) | ||
testStatusLine(t, 99, []byte("HTTP/1.1 99 Unknown Status Code\r\n")) | ||
testStatusLine(t, 200, []byte("HTTP/1.1 200 OK\r\n")) | ||
testStatusLine(t, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n")) | ||
testStatusLine(t, 512, []byte("HTTP/1.1 512 Unknown Status Code\r\n")) | ||
testStatusLine(t, 520, []byte("HTTP/1.1 520 Unknown Status Code\r\n")) | ||
} | ||
|
||
func testStatusLine(t *testing.T, statusCode int, expected []byte) { | ||
line := statusLine(statusCode) | ||
if !bytes.Equal(expected, line) { | ||
t.Fatalf("unexpected status line %s. Expecting %s", string(line), string(expected)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 := statusLine(statusCode) | ||
if !bytes.Equal(expected, line) { | ||
b.Fatalf("unexpected status line %s. Expecting %s", string(line), string(expected)) | ||
} | ||
} | ||
}) | ||
} |