mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
chore: add reflex matcher to the benchmarks (#4520)
Add a test covering stringmatchlen. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
efb7861cee
commit
f2309f4e7b
2 changed files with 77 additions and 0 deletions
|
@ -6,8 +6,14 @@
|
|||
#include "core/intent_lock.h"
|
||||
#include "core/tx_queue.h"
|
||||
|
||||
extern "C" {
|
||||
#include "redis/util.h"
|
||||
}
|
||||
|
||||
namespace dfly {
|
||||
|
||||
using namespace std;
|
||||
|
||||
class TxQueueTest : public ::testing::Test {
|
||||
protected:
|
||||
TxQueueTest() {
|
||||
|
@ -65,4 +71,42 @@ TEST_F(IntentLockTest, Basic) {
|
|||
ASSERT_TRUE(lk_.Check(IntentLock::EXCLUSIVE));
|
||||
}
|
||||
|
||||
class StringMatchTest : public ::testing::Test {
|
||||
protected:
|
||||
// wrapper around stringmatchlen with stringview arguments
|
||||
int MatchLen(string_view pattern, string_view str, bool nocase) {
|
||||
return stringmatchlen(pattern.data(), pattern.size(), str.data(), str.size(), nocase);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(StringMatchTest, Basic) {
|
||||
// ExactMatch
|
||||
EXPECT_EQ(MatchLen("hello", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("hello", "world", 0), 0);
|
||||
|
||||
// Wildcards
|
||||
EXPECT_EQ(MatchLen("*", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h*", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h*o", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("hel*o*", "hello*", 0), 1);
|
||||
|
||||
// Single character wildcard
|
||||
EXPECT_EQ(MatchLen("h[aeiou]llo", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h[aeiou]llo", "hallo", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h[^aeiou]llo", "hallo", 0), 0);
|
||||
EXPECT_EQ(MatchLen("h[a-z]llo", "hello", 0), 1);
|
||||
|
||||
EXPECT_EQ(MatchLen("h[A-Z]llo", "Hello", 1), 1);
|
||||
|
||||
EXPECT_EQ(MatchLen("h\\*llo", "h*llo", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h\\\\llo", "h\\llo", 0), 1);
|
||||
|
||||
// ?
|
||||
EXPECT_EQ(MatchLen("h?llo", "hello", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h??llo", "ha llo", 0), 1);
|
||||
EXPECT_EQ(MatchLen("h??llo", "hallo", 0), 0);
|
||||
EXPECT_EQ(MatchLen("h\\?llo", "hallo", 0), 0);
|
||||
EXPECT_EQ(MatchLen("h\\?llo", "h?llo", 0), 1);
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
|
@ -13,6 +13,7 @@ extern "C" {
|
|||
#include <absl/strings/strip.h>
|
||||
#include <fast_float/fast_float.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <reflex/matcher.h>
|
||||
|
||||
#include "base/flags.h"
|
||||
#include "base/gtest.h"
|
||||
|
@ -891,5 +892,37 @@ static void BM_MatchFindSubstr(benchmark::State& state) {
|
|||
}
|
||||
BENCHMARK(BM_MatchFindSubstr)->Arg(1000)->Arg(10000);
|
||||
|
||||
static void BM_MatchReflexFind(benchmark::State& state) {
|
||||
absl::InsecureBitGen eng;
|
||||
string random_val = GetRandomHex(eng, state.range(0));
|
||||
reflex::Matcher matcher("foobar");
|
||||
matcher.input("xxxxxxfoobaryyyyyyyy");
|
||||
CHECK_GT(matcher.find(), 0u);
|
||||
matcher.input("xxxxxxfoobayyyyyyyy");
|
||||
CHECK_EQ(0u, matcher.find());
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
matcher.input(random_val);
|
||||
DoNotOptimize(matcher.find());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_MatchReflexFind)->Arg(1000)->Arg(10000);
|
||||
|
||||
static void BM_MatchReflexMatch(benchmark::State& state) {
|
||||
absl::InsecureBitGen eng;
|
||||
string random_val = GetRandomHex(eng, state.range(0));
|
||||
reflex::Matcher matcher(".*foobar.*");
|
||||
matcher.input("xxxxxxfoobaryyyyyyyy");
|
||||
CHECK_GT(matcher.matches(), 0u);
|
||||
matcher.input("xxxxxxfoobayyyyyyyy");
|
||||
CHECK_EQ(0u, matcher.matches());
|
||||
|
||||
matcher.input(random_val);
|
||||
while (state.KeepRunning()) {
|
||||
matcher.input(random_val);
|
||||
DoNotOptimize(matcher.matches());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_MatchReflexMatch)->Arg(1000)->Arg(10000);
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue