You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by wo...@apache.org on 2021/01/03 09:41:49 UTC

[dubbo-go-hessian2] 03/03: add benchmark for string decode

This is an automated email from the ASF dual-hosted git repository.

wongoo pushed a commit to branch fix-emoji
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git

commit cc4f9a45ae36b635ed54e61f8e42c9873ca1a740
Author: wangoo <wo...@apache.org>
AuthorDate: Sun Jan 3 17:41:16 2021 +0800

    add benchmark for string decode
---
 string_test.go | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/string_test.go b/string_test.go
index de945f2..1c2666d 100644
--- a/string_test.go
+++ b/string_test.go
@@ -214,8 +214,19 @@ func TestStringComplex(t *testing.T) {
 	testJavaDecode(t, "customArgComplexString", s0)
 }
 
-func BenchmarkDecodeString(b *testing.B) {
-	s := "β„οΈπŸš«πŸš«πŸš«πŸš« 倚欑θ‡ͺζˆ‘δ»‹η»γ€δ»»εŠ‘γ€εŠ¨ζ€ε’Œ"
+func BenchmarkDecodeStringAscii(b *testing.B) {
+	runBenchmarkDecodeString(b, "hello world, hello hessian")
+}
+
+func BenchmarkDecodeStringUnicode(b *testing.B) {
+	runBenchmarkDecodeString(b, "δ½ ε₯½, δΈ–η•Œ, δ½ ε₯½, hessian")
+}
+
+func BenchmarkDecodeStringEmoji(b *testing.B) {
+	runBenchmarkDecodeString(b, "β„οΈπŸš«πŸš«πŸš«πŸš« 倚欑θ‡ͺζˆ‘δ»‹η»γ€δ»»εŠ‘γ€εŠ¨ζ€ε’Œ")
+}
+
+func runBenchmarkDecodeString(b *testing.B, s string) {
 	s = strings.Repeat(s, 4096)
 
 	e := NewEncoder()
@@ -225,6 +236,10 @@ func BenchmarkDecodeString(b *testing.B) {
 	d := NewDecoder(buf)
 	for i := 0; i < b.N; i++ {
 		d.Reset(buf)
-		_, _ = d.Decode()
+		_, err := d.Decode()
+		if err != nil {
+			b.Logf("err: %s", err)
+			b.FailNow()
+		}
 	}
 }