Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TEST_CASE("bench") {
- InMemoryTestFile config;
- config.cache = false;
- auto r = Realm::get_shared_realm(config);
- r->update_schema({
- {"Project", {
- {"id", PropertyType::Int, Property::IsPrimary{true}},
- {"items", PropertyType::Object|PropertyType::Array, "Item"}
- }},
- {"Item", {
- {"id", PropertyType::Int, Property::IsPrimary{true}},
- {"isActive", PropertyType::Bool},
- {"notes", PropertyType::Object|PropertyType::Array, "Note"}
- }},
- {"Note", {
- {"id", PropertyType::Int, Property::IsPrimary{true}},
- {"text", PropertyType::String},
- }},
- });
- r->begin_transaction();
- Table& project_table = *r->read_group().get_table("class_Project");
- Table& item_table = *r->read_group().get_table("class_Item");
- Table& note_table = *r->read_group().get_table("class_Note");
- project_table.add_empty_row();
- item_table.add_empty_row(20000);
- note_table.add_empty_row(80000);
- for (size_t i = 20000; i > 0; --i)
- item_table.set_int_unique(0, i - 1, i - 1);
- for (size_t i = 80000; i > 0; --i)
- note_table.set_int_unique(0, i - 1, i - 1);
- Row project = project_table.get(0);
- LinkViewRef items = project.get_linklist(1);
- for (size_t i = 0; i < 20000; ++i) {
- items->add(i);
- Row item = item_table.get(i);
- LinkViewRef notes = item.get_linklist(2);
- for (size_t j = 0; j < 4; ++j)
- notes->add(i * 4 + j);
- }
- r->commit_transaction();
- List list{r, items};
- auto token = list.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {});
- std::cerr << "Start\n";
- using clock = std::chrono::high_resolution_clock;
- auto start = clock::now();
- for (int i = 0; i < 100; ++i) {
- r->begin_transaction();
- item_table.set_bool(1, 0, item_table.get_bool(1, 0));
- r->commit_transaction();
- }
- auto end = clock::now();
- auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cerr << "Elapsed time: " << duration << "ms\n";
- }
Add Comment
Please, Sign In to add comment