aboutsummaryrefslogtreecommitdiff
path: root/bytesconv_timing_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-11 13:11:15 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-11 13:11:15 +0200
commit3222ab8c8c892740571936ad9e9c3edb25796664 (patch)
tree686cf15ea40627a35485e151ea77e3703a9893f6 /bytesconv_timing_test.go
parentRefer to PathRewriteFunc as net/http.StripPrefix substitution (diff)
downloadfasthttp-3222ab8c8c892740571936ad9e9c3edb25796664.tar.gz
fasthttp-3222ab8c8c892740571936ad9e9c3edb25796664.tar.bz2
fasthttp-3222ab8c8c892740571936ad9e9c3edb25796664.zip
Added AppendIPv4 and ParseIPv4 helper functions
Diffstat (limited to 'bytesconv_timing_test.go')
-rw-r--r--bytesconv_timing_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/bytesconv_timing_test.go b/bytesconv_timing_test.go
index cb6d82a..ef87973 100644
--- a/bytesconv_timing_test.go
+++ b/bytesconv_timing_test.go
@@ -3,9 +3,34 @@ package fasthttp
import (
"bufio"
"bytes"
+ "net"
"testing"
)
+func BenchmarkParseIPv4(b *testing.B) {
+ ipStr := []byte("123.145.167.189")
+ b.RunParallel(func(pb *testing.PB) {
+ var ip net.IP
+ var err error
+ for pb.Next() {
+ ip, err = ParseIPv4(ip, ipStr)
+ if err != nil {
+ b.Fatalf("unexpected error: %s", err)
+ }
+ }
+ })
+}
+
+func BenchmarkAppendIPv4(b *testing.B) {
+ ip := net.ParseIP("123.145.167.189")
+ b.RunParallel(func(pb *testing.PB) {
+ var buf []byte
+ for pb.Next() {
+ buf = AppendIPv4(buf[:0], ip)
+ }
+ })
+}
+
func BenchmarkInt2HexByte(b *testing.B) {
buf := []int{1, 0xf, 2, 0xd, 3, 0xe, 4, 0xa, 5, 0xb, 6, 0xc, 7, 0xf, 0, 0xf, 6, 0xd, 9, 8, 4, 0x5}
b.RunParallel(func(pb *testing.PB) {