-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmark 'add' and 'rm' of generic_mtrie #4574
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
Copyright (c) 2023 Contributors as noted in the AUTHORS file | ||
|
||
This file is part of libzmq, the ZeroMQ core engine in C++. | ||
|
||
libzmq is free software; you can redistribute it and/or modify it under | ||
the terms of the GNU Lesser General Public License (LGPL) as published | ||
by the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
As a special exception, the Contributors give you permission to link | ||
this library with independent modules to produce an executable, | ||
regardless of the license terms of these independent modules, and to | ||
copy and distribute the resulting executable under terms of your choice, | ||
provided that you also meet, for each linked independent module, the | ||
terms and conditions of the license of that module. An independent | ||
module is a module which is not derived from or based on this library. | ||
If you modify this library, you must extend this exception to your | ||
version of the library. | ||
|
||
libzmq is distributed in the hope that it will be useful, but WITHOUT | ||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | ||
License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#if __cplusplus >= 201103L | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this necessary? |
||
|
||
#include "generic_mtrie_impl.hpp" | ||
|
||
#include <chrono> | ||
#include <cstdio> | ||
#include <random> | ||
#include <ratio> | ||
#include <vector> | ||
#include <string> | ||
|
||
const std::size_t nprefix = 1000000; | ||
const std::size_t samples = 10; | ||
|
||
template <class T> | ||
void benchmark_add ( | ||
T &subscriptions_, | ||
std::vector<std::pair<zmq::generic_mtrie_t<uint64_t>::prefix_t, size_t> > | ||
&prefixes_, | ||
uint64_t *pipes_) | ||
{ | ||
using namespace std::chrono; | ||
std::vector<duration<long, std::nano> > samples_vec; | ||
samples_vec.reserve (samples); | ||
|
||
for (std::size_t run = 0; run < samples; ++run) { | ||
duration<long, std::nano> interval (0); | ||
for (std::size_t i = 0; i < prefixes_.size (); i++) { | ||
auto start = steady_clock::now (); | ||
subscriptions_.add (prefixes_[i].first, prefixes_[i].second, | ||
&pipes_[i]); | ||
auto end = steady_clock::now (); | ||
interval += end - start; | ||
} | ||
samples_vec.push_back (interval / prefixes_.size ()); | ||
} | ||
|
||
std::size_t sum = 0; | ||
for (const auto &sample : samples_vec) | ||
sum += sample.count (); | ||
std::printf ("Average operation time = %.1lf ns\n", | ||
static_cast<double> (sum) / samples); | ||
} | ||
|
||
template <class T> | ||
void benchmark_rm ( | ||
T &subscriptions_, | ||
std::vector<std::pair<zmq::generic_mtrie_t<uint64_t>::prefix_t, size_t> > | ||
&prefixes_, | ||
uint64_t *pipes_) | ||
{ | ||
using namespace std::chrono; | ||
std::vector<duration<long, std::nano> > samples_vec; | ||
samples_vec.reserve (samples); | ||
|
||
for (std::size_t run = 0; run < samples; ++run) { | ||
duration<long, std::nano> interval (0); | ||
for (std::size_t i = 0; i < prefixes_.size (); i++) { | ||
auto start = steady_clock::now (); | ||
subscriptions_.rm (prefixes_[i].first, prefixes_[i].second, | ||
&pipes_[i]); | ||
auto end = steady_clock::now (); | ||
interval += end - start; | ||
} | ||
samples_vec.push_back (interval / prefixes_.size ()); | ||
} | ||
|
||
std::size_t sum = 0; | ||
for (const auto &sample : samples_vec) | ||
sum += sample.count (); | ||
std::printf ("Average operation time = %.1lf ns\n", | ||
static_cast<double> (sum) / samples); | ||
} | ||
|
||
int main () | ||
{ | ||
// Generate input set. | ||
uint64_t pipes[nprefix]; | ||
std::vector<std::pair<zmq::generic_mtrie_t<uint64_t>::prefix_t, size_t> > | ||
prefixes; | ||
prefixes.reserve (nprefix); | ||
for (std::size_t i = 0; i < nprefix; ++i) { | ||
char prefix[100]; | ||
size_t len = sprintf (prefix, "prefix_%lu", i); | ||
prefixes.push_back (std::make_pair ( | ||
reinterpret_cast<zmq::generic_mtrie_t<uint64_t>::prefix_t> (prefix), | ||
len)); | ||
} | ||
|
||
// Initialize data structures. | ||
// | ||
// Keeping initialization out of the benchmarking function helps | ||
// heaptrack detect peak memory consumption of the radix tree. | ||
zmq::generic_mtrie_t<uint64_t> mtrie; | ||
|
||
// Create a benchmark. | ||
std::printf ("prefixes = %llu\n", | ||
static_cast<unsigned long long> (nprefix)); | ||
std::puts ("[generic_mtrie::add]"); | ||
benchmark_add (mtrie, prefixes, pipes); | ||
|
||
std::puts ("[generic_mtrie::rm]"); | ||
benchmark_rm (mtrie, prefixes, pipes); | ||
} | ||
|
||
#else | ||
|
||
int main () | ||
{ | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The license has changed, please check other files and update the header to match