From 0cd471dd6d510409d09b652d3e4e37d328d94c5b Mon Sep 17 00:00:00 2001 From: Tong Sun Date: Wed, 28 Jul 2021 08:43:43 -0400 Subject: [PATCH] - [+] add Benchmarks for FormatEmoji --- emoji_test.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/emoji_test.go b/emoji_test.go index fc2595d..cee544e 100644 --- a/emoji_test.go +++ b/emoji_test.go @@ -1,6 +1,9 @@ package openwechat -import "testing" +import ( + "fmt" + "testing" +) func TestFormatEmoji(t *testing.T) { t.Log(FormatEmoji(`多吃点苹果`)) @@ -17,5 +20,27 @@ func TestSendEmoji(t *testing.T) { t.Error(err) return } - _ , _= f.SendText(Emoji.Dagger) + _, _ = f.SendText(Emoji.Dagger) +} + +func BenchmarkFormatEmojiString(b *testing.B) { + str := `多吃点苹果高兴 生气 点赞` + b.SetBytes(int64(len(str))) + // b.N会根据函数的运行时间取一个合适的值 + for i := 0; i < b.N; i++ { + FormatEmoji(str) + } +} + +func BenchmarkFormatEmojiBlock(b *testing.B) { + str := "" + for ii := 0x1F301; ii <= 0x1F53D; ii++ { + str += fmt.Sprintf(` `, ii) + } + b.SetBytes(int64(len(str))) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + FormatEmoji(str) + } }