8000 RCORE-1784 Add new index related benchmarks by ironage · Pull Request #7401 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RCORE-1784 Add new index related benchmarks #7401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 139 additions & 4 deletions test/benchmark-common-tasks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,10 @@ struct BenchmarkWithType : Benchmark {
util::format("%1<%2><%3><%4>", prefix, get_data_type_name(Type::data_type),
Type::is_nullable ? "Nullable" : "NonNullable", Type::is_indexed ? "Indexed" : "NonIndexed");
}
void before_all(DBRef group)
void do_add_perf_data(WriteTransaction& tr, bool add_index)
{
TestValueGenerator gen;
WriteTransaction tr(group);
TableRef t = tr.add_table(name());
TableRef t = tr.get_or_add_table(name());
m_col = t->add_column(Type::data_type, name(), Type::is_nullable);
Random r;
for (size_t i = 0; i < BASE_SIZE / 2; ++i) {
Expand All @@ -542,9 +541,14 @@ struct BenchmarkWithType : Benchmark {
}
needles.push_back(needle);
}
if constexpr (Type::is_indexed) {
if (add_index) {
t->add_search_index(m_col);
}
}
void before_all(DBRef group)
{
WriteTransaction tr(group);
do_add_perf_data(tr, Type::is_indexed);
tr.commit();
}

Expand Down Expand Up @@ -634,6 +638,118 @@ struct BenchmarkRangeForType : public BenchmarkWithType<Type> {
}
};

template <typename Type>
struct BenchmarkCreateIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkCreateIndexForType<Type>()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("CreateIndexFor");
}
void before_all(DBRef group) override
{
WriteTransaction tr(group);
constexpr bool add_index = false;
BenchmarkWithType<Type>::do_add_perf_data(tr, add_index);
tr.commit();
}
void operator()(DBRef) override
{
Benchmark::m_table->add_search_index(Benchmark::m_col);
}
};

template <typename Type>
struct BenchmarkInsertToIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkInsertToIndexForType<Type>()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("InsertWithIndex");
}
void before_all(DBRef group) override
{
WriteTransaction tr(group);
TableRef t = tr.get_or_add_table(Base::name());
Base::m_col = t->add_column(Type::data_type, Base::name(), Type::is_nullable);
if (Type::is_indexed) {
t->add_search_index(Base::m_col);
}
tr.commit();
m_random_values.reserve(BASE_SIZE / 2);
for (size_t i = 0; i < BASE_SIZE / 2; ++i) {
int64_t randomness = m_random.draw_int<int64_t>();
m_random_values.push_back(m_test_value_generator.convert_for_test<underlying_type>(randomness));
}
}
void operator()(DBRef) override
{
for (auto it = m_random_values.begin(); it != m_random_values.end(); ++it) {
// a hand full of duplicates
Base::m_table->create_object().set_any(Base::m_col, *it);
Base::m_table->create_object().set_any(Base::m_col, *it);
}
}
std::vector<Mixed> m_random_values;
TestValueGenerator m_test_value_generator;
Random m_random;
};

template <typename Type>
struct BenchmarkInsertPKToIndexForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkInsertPKToIndexForType<Type>()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("InsertPK");
}
void before_all(DBRef group) override
{
WriteTransaction tr(group);
TableRef t = tr.get_or_add_table(Base::name());
Base::m_col = t->add_column(Type::data_type, Base::name(), Type::is_nullable);
t->set_primary_key_column(Base::m_col);
REALM_ASSERT(t->has_search_index(Base::m_col));
tr.commit();
while (m_unique_randoms.size() < BASE_SIZE) {
int64_t random_int = m_random.draw_int<int64_t>();
m_unique_randoms.insert(m_test_value_generator.convert_for_test<underlying_type>(random_int));
}
}
void operator()(DBRef) override
{
for (auto it = m_unique_randoms.begin(); it != m_unique_randoms.end(); ++it) {
Base::m_table->create_object_with_primary_key(*it);
}
}
TestValueGenerator m_test_value_generator;
Random m_random;
std::set<underlying_type> m_unique_randoms;
};

template <typename Type>
struct BenchmarkEraseObjectForType : public BenchmarkWithType<Type> {
using Base = BenchmarkWithType<Type>;
using underlying_type = typename Type::underlying_type;
BenchmarkEraseObjectForType<Type>()
: BenchmarkWithType<Type>()
{
BenchmarkWithType<Type>::set_name_with_prefix("EraseObject");
}
void before_all(DBRef group) override
{
Base::before_all(group);
}
void operator()(DBRef) override
{
while (!Base::m_table->is_empty()) {
Base::m_table->begin()->remove();
}
}
};

struct BenchmarkWithTimestamps : Benchmark {
std::multiset<Timestamp> values;
Expand Down Expand Up @@ -2494,6 +2610,8 @@ int benchmark_common_tasks_main()
BENCH(BenchmarkWithType<Prop<ObjectId>>);
BENCH(BenchmarkWithType<Indexed<Timestamp>>);
BENCH(BenchmarkWithType<Prop<Timestamp>>);
BENCH(BenchmarkWithType<Indexed<Int>>);
BENCH(BenchmarkWithType<Indexed<String>>);
BENCH(BenchmarkWithType<Indexed<Bool>>);
BENCH(BenchmarkWithType<Prop<Bool>>);
BENCH(BenchmarkMixedCaseInsensitiveEqual<Prop<Mixed>>);
Expand All @@ -2502,6 +2620,23 @@ int benchmark_common_tasks_main()
BENCH(BenchmarkMixedCaseInsensitiveEqual<Indexed<String>>);

BENCH(BenchmarkRangeForType<Prop<Int>>);
BENCH(BenchmarkCreateIndexForType<NullableIndexed<String>>);
BENCH(BenchmarkCreateIndexForType<NullableIndexed<Int>>);
BENCH(BenchmarkCreateIndexForType<NullableIndexed<Timestamp>>);

BENCH(BenchmarkInsertToIndexForType<NullableIndexed<String>>);
BENCH(BenchmarkInsertToIndexForType<NullableIndexed<Int>>);
BENCH(BenchmarkInsertToIndexForType<NullableIndexed<Timestamp>>);

BENCH(BenchmarkInsertPKToIndexForType<NullableIndexed<String>>);
BENCH(BenchmarkInsertPKToIndexForType<NullableIndexed<Int>>);

BENCH(BenchmarkEraseObjectForType<Prop<String>>);
BENCH(BenchmarkEraseObjectForType<Prop<Int>>);
BENCH(BenchmarkEraseObjectForType<Prop<Timestamp>>);
BENCH(BenchmarkEraseObjectForType<NullableIndexed<String>>);
BENCH(BenchmarkEraseObjectForType<NullableIndexed<Int>>);
BENCH(BenchmarkEraseObjectForType<NullableIndexed<Timestamp>>);

BENCH(BenchmarkQueryTimestampGreaterOverLinks);
BENCH(BenchmarkQueryTimestampGreater);
Expand Down
0