aboutsummaryrefslogtreecommitdiff
path: root/bytesconv_timing_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-15 16:53:44 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-15 16:53:44 +0200
commit394c20fdc5cdf3ae65415218705b6e59b8a7c344 (patch)
tree817a0b4d3c352c289a643f05c9c209bfbf229f90 /bytesconv_timing_test.go
parentIssue #52: updated client benchmark results in readme (diff)
downloadfasthttp-394c20fdc5cdf3ae65415218705b6e59b8a7c344.tar.gz
fasthttp-394c20fdc5cdf3ae65415218705b6e59b8a7c344.tar.bz2
fasthttp-394c20fdc5cdf3ae65415218705b6e59b8a7c344.zip
Added AppendHTMLEscape helper function
Diffstat (limited to 'bytesconv_timing_test.go')
-rw-r--r--bytesconv_timing_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/bytesconv_timing_test.go b/bytesconv_timing_test.go
index e233502..bd416d1 100644
--- a/bytesconv_timing_test.go
+++ b/bytesconv_timing_test.go
@@ -2,10 +2,43 @@ package fasthttp
import (
"bufio"
+ "html"
"net"
"testing"
)
+func BenchmarkAppendHTMLEscape(b *testing.B) {
+ sOrig := "<b>foobarbazxxxyyyzzz</b>"
+ sExpected := string(AppendHTMLEscape(nil, sOrig))
+ b.RunParallel(func(pb *testing.PB) {
+ var buf []byte
+ for pb.Next() {
+ for i := 0; i < 10; i++ {
+ buf = AppendHTMLEscape(buf[:0], sOrig)
+ if string(buf) != sExpected {
+ b.Fatalf("unexpected escaped string: %s. Expecting %s", buf, sExpected)
+ }
+ }
+ }
+ })
+}
+
+func BenchmarkHTMLEscapeString(b *testing.B) {
+ sOrig := "<b>foobarbazxxxyyyzzz</b>"
+ sExpected := html.EscapeString(sOrig)
+ b.RunParallel(func(pb *testing.PB) {
+ var s string
+ for pb.Next() {
+ for i := 0; i < 10; i++ {
+ s = html.EscapeString(sOrig)
+ if s != sExpected {
+ b.Fatalf("unexpected escaped string: %s. Expecting %s", s, sExpected)
+ }
+ }
+ }
+ })
+}
+
func BenchmarkParseIPv4(b *testing.B) {
ipStr := []byte("123.145.167.189")
b.RunParallel(func(pb *testing.PB) {