Created
September 2, 2018 05:31
-
-
Save BillyONeal/8691d0dc6a9437b44d71df303bad7a2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <string> | |
#include <iterator> | |
#include <list> | |
#include <vector> | |
#include <random> | |
#include <benchmark/benchmark.h> | |
using std::string; | |
using std::vector; | |
using std::list; | |
using std::size; | |
using std::random_device; | |
using std::uniform_int_distribution; | |
const int stringSize = 20; | |
const int stringCount = 10000; | |
const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |
struct DataFixture { | |
vector<string> data; | |
DataFixture() { | |
random_device rd; | |
uniform_int_distribution<int> dist(0, size(letters) - 1); | |
data.reserve(stringCount); | |
for (int str = 0; str < stringCount; ++str) { | |
for (char& ch : data.emplace_back(stringSize, '\0')) { | |
ch = letters[dist(rd)]; | |
} | |
} | |
} | |
}; | |
DataFixture fixture; | |
void ListAssign(benchmark::State& state) { | |
list<string> unitUnderTest; | |
for (auto&& _ : state) { | |
(void)_; | |
unitUnderTest.assign(fixture.data.begin(), fixture.data.end()); | |
} | |
} | |
BENCHMARK(ListAssign); | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment