Fix emoji unified/non-qualified version for sending & parsing (#4840)
Co-authored-by: nerix <nerixdev@outlook.de>
This commit is contained in:
@@ -55,3 +55,120 @@ static void BM_ShortcodeParsing(benchmark::State &state)
|
||||
}
|
||||
|
||||
BENCHMARK(BM_ShortcodeParsing);
|
||||
|
||||
static void BM_EmojiParsing(benchmark::State &state)
|
||||
{
|
||||
Emojis emojis;
|
||||
|
||||
emojis.load();
|
||||
|
||||
struct TestCase {
|
||||
QString input;
|
||||
std::vector<boost::variant<EmotePtr, QString>> expectedOutput;
|
||||
};
|
||||
|
||||
const auto &emojiMap = emojis.getEmojis();
|
||||
std::shared_ptr<EmojiData> penguin;
|
||||
emojiMap.tryGet("1F427", penguin);
|
||||
auto penguinEmoji = penguin->emote;
|
||||
|
||||
std::vector<TestCase> tests{
|
||||
{
|
||||
// 1 emoji
|
||||
"foo 🐧 bar",
|
||||
// expected output
|
||||
{
|
||||
"foo ",
|
||||
penguinEmoji,
|
||||
" bar",
|
||||
},
|
||||
},
|
||||
{
|
||||
// no emoji
|
||||
"foo bar",
|
||||
// expected output
|
||||
{
|
||||
"foo bar",
|
||||
},
|
||||
},
|
||||
{
|
||||
// many emoji
|
||||
"foo 🐧 bar 🐧🐧🐧🐧🐧",
|
||||
// expected output
|
||||
{
|
||||
"foo ",
|
||||
penguinEmoji,
|
||||
" bar ",
|
||||
penguinEmoji,
|
||||
penguinEmoji,
|
||||
penguinEmoji,
|
||||
penguinEmoji,
|
||||
penguinEmoji,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
for (auto _ : state)
|
||||
{
|
||||
for (const auto &test : tests)
|
||||
{
|
||||
auto output = emojis.parse(test.input);
|
||||
|
||||
bool areEqual = std::equal(output.begin(), output.end(),
|
||||
test.expectedOutput.begin());
|
||||
|
||||
if (!areEqual)
|
||||
{
|
||||
qDebug() << "BAD BENCH";
|
||||
for (const auto &v : output)
|
||||
{
|
||||
if (v.type() == typeid(QString))
|
||||
{
|
||||
qDebug() << "output:" << boost::get<QString>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_EmojiParsing);
|
||||
|
||||
template <class... Args>
|
||||
static void BM_EmojiParsing2(benchmark::State &state, Args &&...args)
|
||||
{
|
||||
Emojis emojis;
|
||||
|
||||
emojis.load();
|
||||
|
||||
auto argsTuple = std::make_tuple(std::move(args)...);
|
||||
auto input = std::get<0>(argsTuple);
|
||||
auto expectedNumEmojis = std::get<1>(argsTuple);
|
||||
for (auto _ : state)
|
||||
{
|
||||
auto output = emojis.parse(input);
|
||||
int actualNumEmojis = 0;
|
||||
for (const auto &part : output)
|
||||
{
|
||||
if (part.type() == typeid(EmotePtr))
|
||||
{
|
||||
++actualNumEmojis;
|
||||
}
|
||||
}
|
||||
|
||||
if (actualNumEmojis != expectedNumEmojis)
|
||||
{
|
||||
qDebug() << "BAD BENCH, EXPECTED NUM EMOJIS IS WRONG"
|
||||
<< actualNumEmojis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CAPTURE(BM_EmojiParsing2, one_emoji, "foo 🐧 bar", 1);
|
||||
BENCHMARK_CAPTURE(BM_EmojiParsing2, two_emoji, "foo 🐧 bar 🐧", 2);
|
||||
BENCHMARK_CAPTURE(
|
||||
BM_EmojiParsing2, many_emoji,
|
||||
"😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 "
|
||||
"😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 "
|
||||
"😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 ",
|
||||
61);
|
||||
|
||||
Reference in New Issue
Block a user