Created
July 26, 2016 19:54
-
-
Save aldanor/00090b065f3df754d836575e42d7293e to your computer and use it in GitHub Desktop.
LLVM SmallVector
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
#include "llvm/ADT/SmallVector.h" | |
#include <array> | |
#include <chrono> | |
#include <cstdint> | |
#include <iostream> | |
#include <vector> | |
struct Message { std::array<char, 128> data { }; }; | |
template<bool fast> struct Packet { }; | |
template<> struct Packet<false> { std::vector<Message> messages; }; | |
template<> struct Packet<true> { llvm::SmallVector<Message, 3> messages; }; | |
template<bool fast> void bench(size_t N) { | |
using namespace std::chrono; | |
std::cout << "Running, N = " << N << ", fast = " << fast << "... "; | |
auto t0 = high_resolution_clock::now(); | |
Message m; | |
for (size_t i = 0; i < N; i++) { | |
Packet<fast> p; | |
p.messages.push_back(m); p.messages.push_back(m); p.messages.push_back(m); | |
} | |
auto t1 = high_resolution_clock::now(); | |
auto d = duration_cast<microseconds>(t1 - t0).count(); | |
std::cout << "elapsed: " << d << " µs" << std::endl; | |
} | |
int main() { | |
bench<false>(1000); bench<true>(1000); | |
bench<false>(10000); bench<true>(10000); | |
bench<false>(100000); bench<true>(100000); | |
} |
Author
aldanor
commented
Jul 26, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment