[benchmark-set] Add benchmark for set copy

This commit is contained in:
Behdad Esfahbod 2022-05-19 14:12:42 -06:00
parent 44952bcc25
commit 0623aa598b
2 changed files with 27 additions and 4 deletions

View File

@ -120,4 +120,27 @@ BENCHMARK(BM_SetIteration)
{{1 << 10, 1 << 16}, // Set Size
{2, 512}}); // Density
/* Set copy. */
static void BM_SetCopy(benchmark::State& state) {
unsigned set_size = state.range(0);
unsigned max_value = state.range(0) * state.range(1);
hb_set_t* original = hb_set_create ();
RandomSet(set_size, max_value, original);
assert(hb_set_get_population(original) == set_size);
for (auto _ : state) {
hb_set_t *s = hb_set_create ();
hb_set_set (s, original);
hb_set_destroy (s);
}
hb_set_destroy(original);
}
BENCHMARK(BM_SetCopy)
->Unit(benchmark::kMicrosecond)
->Ranges(
{{1 << 10, 1 << 16}, // Set Size
{2, 512}}); // Density
BENCHMARK_MAIN();

View File

@ -43,8 +43,8 @@ struct hb_sparseset_t
hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); }
hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = std::move (other.s); }
hb_sparseset_t& operator= (const hb_sparseset_t& other) { set (other); return *this; }
hb_sparseset_t& operator= (hb_sparseset_t&& other) { s = std::move (other.s); return *this; }
hb_sparseset_t& operator = (const hb_sparseset_t& other) { set (other); return *this; }
hb_sparseset_t& operator = (hb_sparseset_t&& other) { s = std::move (other.s); return *this; }
friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); }
hb_sparseset_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t ()
@ -169,8 +169,8 @@ struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
hb_set_t (std::nullptr_t) : hb_set_t () {};
hb_set_t (const hb_set_t &o) : sparseset ((sparseset &) o) {};
hb_set_t (hb_set_t&& o) : sparseset (std::move ((sparseset &) o)) {}
hb_set_t& operator= (const hb_set_t&) = default;
hb_set_t& operator= (hb_set_t&&) = default;
hb_set_t& operator = (const hb_set_t&) = default;
hb_set_t& operator = (hb_set_t&&) = default;
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : sparseset (lst) {}
template <typename Iterable,
hb_requires (hb_is_iterable (Iterable))>