52volatile long sink = 0;
61 const auto t0 = std::chrono::steady_clock::now();
63 const auto t1 = std::chrono::steady_clock::now();
65 std::chrono::duration<double, std::milli>(
t1 -
t0).count();
71void row(
const char *container,
const char *op,
double ms)
73 std::printf(
" %-12s %-24s %10.2f ms\n", container, op,
ms);
78 std::vector<long>
keys(n);
80 std::shuffle(
keys.begin(),
keys.end(), std::mt19937(
seed));
86 std::printf(
"\n== Ordered sets (lookup/iteration size %zu, incremental "
93 row(
"FlatSet",
"bulk build",
95 sink +=
static_cast<long>(s.size()); }));
96 row(
"DynSetTree",
"bulk build",
99 sink +=
static_cast<long>(s.
size()); }));
100 row(
"std::set",
"bulk build",
102 sink +=
static_cast<long>(s.
size()); }));
105 row(
"FlatSet",
"random insert",
108 sink +=
static_cast<long>(s.
size()); }));
109 row(
"DynSetTree",
"random insert",
112 sink +=
static_cast<long>(s.
size()); }));
113 row(
"std::set",
"random insert",
114 best_ms([&] { std::set<long> s;
116 sink +=
static_cast<long>(s.size()); }));
121 for (
const long k :
keys)
124 const long span = 2 *
static_cast<long>(
lookup_n);
126 row(
"FlatSet",
"lookup 50% hits",
128 for (
long k = 0;
k < span; ++
k) hits += fs.contains(
k);
130 row(
"DynSetTree",
"lookup 50% hits",
132 for (
long k = 0;
k < span; ++
k) hits +=
ts.contains(
k);
134 row(
"std::set",
"lookup 50% hits",
136 for (
long k = 0;
k < span; ++
k) hits +=
ss.count(
k);
140 row(
"FlatSet",
"iterate + sum",
142 for (
const long k : fs)
acc +=
k;
144 row(
"DynSetTree",
"iterate + sum",
146 ts.for_each([&
acc] (
const long &
k) {
acc +=
k; });
148 row(
"std::set",
"iterate + sum",
150 for (
const long k :
ss)
acc +=
k;
156 std::printf(
"\n== Ordered maps (lookup size %zu, incremental insert size "
162 row(
"FlatMap",
"random insert",
165 sink +=
static_cast<long>(
m.
size()); }));
166 row(
"DynMapTree",
"random insert",
169 sink +=
static_cast<long>(
m.
size()); }));
170 row(
"std::map",
"random insert",
171 best_ms([&] { std::map<long, long>
m;
173 sink +=
static_cast<long>(
m.
size()); }));
176 for (
const long k :
keys)
179 for (
const long k :
keys)
181 std::map<long, long>
sm;
182 for (
const long k :
keys)
184 const long span = 2 *
static_cast<long>(
lookup_n);
186 row(
"FlatMap",
"lookup 50% hits",
188 for (
long k = 0;
k < span; ++
k) hits +=
fm.contains(
k);
190 row(
"DynMapTree",
"lookup 50% hits",
192 for (
long k = 0;
k < span; ++
k) hits +=
tm.contains(
k);
194 row(
"std::map",
"lookup 50% hits",
196 for (
long k = 0;
k < span; ++
k) hits +=
sm.count(
k);
199 row(
"FlatMap",
"iterate + sum values",
201 for (
auto [
k, v] :
fm)
acc += v;
203 row(
"DynMapTree",
"iterate + sum values",
205 tm.for_each([&
acc] (
const std::pair<long, long> &p)
206 {
acc += p.second; });
208 row(
"std::map",
"iterate + sum values",
210 for (
const auto &[
k, v] :
sm)
acc += v;
216 std::printf(
"\n== Small sequences (%zu rounds of 8 appends each) ==\n",
219 row(
"SmallVector",
"build 8-elem seq",
224 for (
long i = 0; i < 8; ++i)
225 v.
append(i +
static_cast<long>(
r));
229 row(
"std::vector",
"build 8-elem seq",
234 for (
long i = 0; i < 8; ++i)
235 v.push_back(i +
static_cast<long>(
r));
243 std::printf(
"\n== Sliding window over a stream of %zu samples "
245 constexpr size_t window = 1024;
247 row(
"RingBuffer",
"put_overwrite stream",
249 for (
size_t i = 0; i <
stream_n; ++i)
250 rb.put_overwrite(
static_cast<long>(i));
251 sink +=
rb.get_last(); }));
252 row(
"std::deque",
"bounded push/pop",
254 for (
size_t i = 0; i <
stream_n; ++i)
256 dq.push_back(
static_cast<long>(i));
257 if (
dq.size() > window)
260 sink +=
dq.back(); }));
272 std::printf(
"Flat containers benchmark (best of 3 runs)\n");
277 std::printf(
"\n(sink=%ld)\n",
static_cast<long>(sink));
Generic key-value map implemented on top of a binary search tree.
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
Ordered map stored as two parallel sorted contiguous arrays.
Ordered set stored as a sorted contiguous array.
size_t size() const noexcept
Return the number of stored keys. O(1).
Fixed-capacity circular FIFO buffer over contiguous storage.
Contiguous dynamic array with N elements of inline storage.
T & get_last()
Last element (checked).
T & append(const T &item)
Append a copy of item.
constexpr size_t size() const noexcept
Returns the number of entries in the table.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Dynamic key-value map based on balanced binary search trees.
Dynamic set implementations based on balanced binary search trees.
Sorted-array map (Aleph::FlatMap), a cache-friendly ordered map.
Sorted-array set (Aleph::FlatSet), a cache-friendly ordered set.
Bounded circular buffer (Aleph::RingBuffer) for FIFO streaming.
Dynamic array with inline storage (Aleph::SmallVector).