aboutsummaryrefslogtreecommitdiff
path: root/status_timing_test.go
diff options
context:
space:
mode:
authorGravatar kiyon <kiyon@gofiber.io> 2020-08-03 01:18:57 +0800
committerGravatar GitHub <noreply@github.com> 2020-08-02 19:18:57 +0200
commit2509c12e7794859d16e359be0fe62a08a5d382d3 (patch)
treeab6611d1f3e70f8b745df5464d1a6d5538553a4a /status_timing_test.go
parentFix comment typo (diff)
downloadfasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.tar.gz
fasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.tar.bz2
fasthttp-2509c12e7794859d16e359be0fe62a08a5d382d3.zip
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>
Diffstat (limited to 'status_timing_test.go')
-rw-r--r--status_timing_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/status_timing_test.go b/status_timing_test.go
new file mode 100644
index 0000000..42b1c91
--- /dev/null
+++ b/status_timing_test.go
@@ -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))
+ }
+ }
+ })
+}