Skip to content

Commit

Permalink
bench: replace vector to pmr::vector
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed May 21, 2024
1 parent 4a378bf commit 5697573
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions bench/bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

struct S {
S() = default;
explicit S(const std::vector<unsigned char>& vec, unsigned long value) : a(vec), b(value) {}
explicit S(const std::pmr::vector<unsigned char>& vec, unsigned long value) : a(vec), b(value) {}

std::vector<unsigned char> a;
std::pmr::vector<unsigned char> a;
unsigned long b;
};

Expand Down Expand Up @@ -43,7 +43,7 @@ int main() {

for (int i = 1; i < 1000; ++i) {
const auto n = dist(rng);
cache[n] = S(std::vector<unsigned char>(12), n);
cache[n] = S(std::pmr::vector<unsigned char>(12), n);
}

for (int i = 1; i < 1000; ++i) {
Expand All @@ -65,7 +65,7 @@ int main() {

for (int i = 1; i < 1000; ++i) {
const auto n = dist(rng);
cache[n] = S(std::vector<unsigned char>(12), n);
cache[n] = S(std::pmr::vector<unsigned char>(12), n);
}

for (int i = 1; i < 1000; ++i) {
Expand Down
10 changes: 6 additions & 4 deletions bench/bench_mimalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class MimallocMemoryResource : public std::pmr::memory_resource {

struct S {
S() = default;
explicit S(const std::vector<unsigned char>& vec, unsigned long value) : a(vec), b(value) {}
explicit S(const std::pmr::vector<unsigned char>& vec, unsigned long value) : a(vec), b(value) {}

std::vector<unsigned char> a;
std::pmr::vector<unsigned char> a;
unsigned long b;
};

Expand Down Expand Up @@ -57,10 +57,11 @@ int main() {
SieveCache<unsigned long, S> cache(68, &mi);
std::mt19937 rng(std::random_device{}());
std::uniform_int_distribution<unsigned long> dist(0, 99);
std::pmr::polymorphic_allocator<unsigned char> pa{&mi};

for (int i = 1; i < 1000; ++i) {
const auto n = dist(rng);
cache[n] = S(std::vector<unsigned char>(12), n);
cache[n] = S(std::pmr::vector<unsigned char>(12, pa), n);
}

for (int i = 1; i < 1000; ++i) {
Expand All @@ -79,10 +80,11 @@ int main() {
SieveCache<unsigned long, S> cache(static_cast<size_t>(SIGMA), &mi);
std::mt19937 rng(std::random_device{}());
std::uniform_int_distribution<unsigned long> dist(0, 99);
std::pmr::polymorphic_allocator<unsigned char> pa{&mi};

for (int i = 1; i < 1000; ++i) {
const auto n = dist(rng);
cache[n] = S(std::vector<unsigned char>(12), n);
cache[n] = S(std::pmr::vector<unsigned char>(12, pa), n);
}

for (int i = 1; i < 1000; ++i) {
Expand Down

0 comments on commit 5697573

Please sign in to comment.