Guest User

Untitled

a guest
Nov 17th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. TEST_CASE("bench") {
  2. InMemoryTestFile config;
  3. config.cache = false;
  4.  
  5. auto r = Realm::get_shared_realm(config);
  6. r->update_schema({
  7. {"Project", {
  8. {"id", PropertyType::Int, Property::IsPrimary{true}},
  9. {"items", PropertyType::Object|PropertyType::Array, "Item"}
  10. }},
  11. {"Item", {
  12. {"id", PropertyType::Int, Property::IsPrimary{true}},
  13. {"isActive", PropertyType::Bool},
  14. {"notes", PropertyType::Object|PropertyType::Array, "Note"}
  15. }},
  16. {"Note", {
  17. {"id", PropertyType::Int, Property::IsPrimary{true}},
  18. {"text", PropertyType::String},
  19. }},
  20. });
  21.  
  22. r->begin_transaction();
  23. Table& project_table = *r->read_group().get_table("class_Project");
  24. Table& item_table = *r->read_group().get_table("class_Item");
  25. Table& note_table = *r->read_group().get_table("class_Note");
  26. project_table.add_empty_row();
  27. item_table.add_empty_row(20000);
  28. note_table.add_empty_row(80000);
  29.  
  30. for (size_t i = 20000; i > 0; --i)
  31. item_table.set_int_unique(0, i - 1, i - 1);
  32. for (size_t i = 80000; i > 0; --i)
  33. note_table.set_int_unique(0, i - 1, i - 1);
  34.  
  35. Row project = project_table.get(0);
  36. LinkViewRef items = project.get_linklist(1);
  37. for (size_t i = 0; i < 20000; ++i) {
  38. items->add(i);
  39. Row item = item_table.get(i);
  40. LinkViewRef notes = item.get_linklist(2);
  41. for (size_t j = 0; j < 4; ++j)
  42. notes->add(i * 4 + j);
  43. }
  44. r->commit_transaction();
  45.  
  46. List list{r, items};
  47. auto token = list.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {});
  48.  
  49. std::cerr << "Start\n";
  50. using clock = std::chrono::high_resolution_clock;
  51. auto start = clock::now();
  52. for (int i = 0; i < 100; ++i) {
  53. r->begin_transaction();
  54. item_table.set_bool(1, 0, item_table.get_bool(1, 0));
  55. r->commit_transaction();
  56. }
  57. auto end = clock::now();
  58. auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
  59. std::cerr << "Elapsed time: " << duration << "ms\n";
  60. }
Add Comment
Please, Sign In to add comment