diff options
author | Michel Hermier <michel.hermier@gmail.com> | 2021-12-23 12:38:22 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-24 05:55:34 -0800 |
commit | 44a6d7968a00f2b70720897d660f1512e3645416 (patch) | |
tree | 52635e761e4775e97308f2b8668372e9be27a319 /Tests/AK | |
parent | 3a177b9209360dcd48d6a9eab8b8b88fd47dea77 (diff) | |
download | serenity-44a6d7968a00f2b70720897d660f1512e3645416.zip |
Tests: Benchmark `DisjointChunck::is_empty`
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/TestDisjointChunks.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Tests/AK/TestDisjointChunks.cpp b/Tests/AK/TestDisjointChunks.cpp index 0d6c1d1f21..e8897d2a15 100644 --- a/Tests/AK/TestDisjointChunks.cpp +++ b/Tests/AK/TestDisjointChunks.cpp @@ -80,3 +80,59 @@ TEST_CASE(spans) EXPECT_EQ(it, cross_chunk_slice.end()); } + +#define INIT_ITERATIONS (1'000'000) +#define ITERATIONS (100) + +static DisjointChunks<int> basic_really_empty_chunks; + +BENCHMARK_CASE(basic_really_empty) +{ + DisjointChunks<int> chunks; + for (size_t i = 0; i < ITERATIONS; ++i) + EXPECT(chunks.is_empty()); +} + +static DisjointChunks<int> basic_really_empty_large_chunks = []() { + DisjointChunks<int> chunks; + chunks.ensure_capacity(INIT_ITERATIONS); + for (size_t i = 0; i < INIT_ITERATIONS; ++i) + chunks.append({}); + return chunks; +}(); + +BENCHMARK_CASE(basic_really_empty_large) +{ + for (size_t i = 0; i < ITERATIONS; ++i) + EXPECT(basic_really_empty_large_chunks.is_empty()); +} + +static DisjointChunks<int> basic_mostly_empty_chunks = []() { + DisjointChunks<int> chunks; + chunks.ensure_capacity(INIT_ITERATIONS + 1); + for (size_t i = 0; i < INIT_ITERATIONS; ++i) + chunks.append({}); + chunks.append({ 1, 2, 3 }); + return chunks; +}(); + +BENCHMARK_CASE(basic_mostly_empty) +{ + for (size_t i = 0; i < ITERATIONS; ++i) { + EXPECT(!basic_mostly_empty_chunks.is_empty()); + } +} + +static DisjointChunks<int> basic_full_chunks = []() { + DisjointChunks<int> chunks; + chunks.ensure_capacity(INIT_ITERATIONS + 1); + for (size_t i = 0; i < INIT_ITERATIONS; ++i) + chunks.append({ 1, 2, 3 }); + return chunks; +}(); + +BENCHMARK_CASE(basic_full) +{ + for (size_t i = 0; i < ITERATIONS; ++i) + EXPECT(!basic_full_chunks.is_empty()); +} |