message: Add benchmark for non-initiator open of a shared group
diff: @@ -61,6 +61,10 @@ const size_t max_repetitions = 1000;
  const double min_duration_s = 0.1;
  const double min_warmup_time_s = 0.05;
  +const char* to_lead_cstr(RealmDurability level);
  +const char* to_ident_cstr(RealmDurability level);
  +
  +
  struct Benchmark {
  virtual ~Benchmark()
  {
  @@ -79,6 +83,8 @@ struct Benchmark {
  {
  }
  virtual void operator()(SharedGroup&) = 0;
  + RealmDurability m_durability = RealmDurability::Full;
  + const char* m_encryption_key = nullptr;
  };
  struct BenchmarkUnorderedTableViewClear : Benchmark {
  @@ -786,6 +792,52 @@ struct BenchmarkGetLinkList : Benchmark {
  }
  };
  +struct BenchmarkNonInitatorOpen : Benchmark {
  + const char* name() const
  + {
  + return "NonInitiatorOpen";
  + }
  + // the shared realm will be removed after the benchmark finishes
  + std::unique_ptr<realm::test_util::SharedGroupTestPathGuard> path;
  + std::unique_ptr<SharedGroup> initiator;
  +
  + std::unique_ptr<SharedGroup> do_open()
  + {
  + const std::string realm_path = *path;
  + return std::unique_ptr<SharedGroup>(create_new_shared_group(realm_path, m_durability, m_encryption_key));
  + }
  +
  + void before_all(SharedGroup&)
  + {
  + // Generate the benchmark result texts:
  + std::stringstream ident_ss;
  + ident_ss << "BenchmarkCommonTasks_" << this->name()
  + << "_" << to_ident_cstr(m_durability);
  + std::string ident = ident_ss.str();
  +
  + realm::test_util::unit_test::TestDetails test_details;
  + test_details.suite_name = "BenchmarkCommonTasks";
  + test_details.test_name = ident.c_str();
  + test_details.file_name = __FILE__;
  + test_details.line_number = __LINE__;
  +
  + path = std::unique_ptr<realm::test_util::SharedGroupTestPathGuard>(new realm::test_util::SharedGroupTestPathGuard(ident));
  +
  + // open once - session initiation
  + initiator = do_open();
  + }
  +
  + void operator()(SharedGroup&)
  + {
  + // use groups of 10 to get higher times
  + for (size_t i = 0; i < 10; ++i) {
  + do_open();
  + // let it close, otherwise we get error: too many open files
  + }
  + }
  +};
  +
  +
  const char* to_lead_cstr(RealmDurability level)
  {
  switch (level) {
  @@ -855,6 +907,8 @@ void run_benchmark(BenchmarkResults& results)
  RealmDurability level = it->first;
  const char* key = it->second;
  B benchmark;
  + benchmark.m_durability = level;
  + benchmark.m_encryption_key = key;
  // Generate the benchmark result texts:
  std::stringstream lead_text_ss;
  @@ -948,6 +1002,7 @@ int benchmark_common_tasks_main()
  BENCH(BenchmarkGetLinkList);
  BENCH(BenchmarkQueryInsensitiveString);
  BENCH(BenchmarkQueryInsensitiveStringIndexed);
  + BENCH(BenchmarkNonInitatorOpen);
  #undef BENCH
  return 0;
  