|
@ -48,59 +48,28 @@ std::vector<uint64_t> common_code_samples(uint64_t num) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// std::vector<uint64_t> select_codes(uint64_t num) {
|
|
|
std::vector<uint32_t> short_code_samples(uint64_t num) { |
|
|
// auto codes = all_common_codes();
|
|
|
|
|
|
//
|
|
|
uint32_t part_size = klotski::codec::SHORT_CODE_LIMIT / num; |
|
|
// // return {codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411]};
|
|
|
|
|
|
// // std::array<uint64_t, 140> samples = {
|
|
|
// uint64_t offset = 0;
|
|
|
// std::vector<uint64_t> samples = {
|
|
|
uint32_t offset = part_size / 2; |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
std::vector<uint32_t> result; |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
for (uint32_t i = 0; i < num; ++i) { |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
uint32_t index = i * part_size + offset; |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
// // std::cout << "index = " << index << std::endl;
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
// uint64_t kk[] {343, 666, 114514, 35324, 123454, 76453, 93411};
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
// uint64_t index = kk[i % 7];
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
//
|
|
|
result.emplace_back(index); |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
} |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
return result; |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
} |
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
//
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
//
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411],
|
|
|
|
|
|
// };
|
|
|
|
|
|
//
|
|
|
|
|
|
// return {samples.begin(), samples.begin() + num};
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> str_common_codes(uint64_t num, bool shorten) { |
|
|
std::vector<std::string> str_common_codes(uint64_t num, bool shorten) { |
|
|
// auto src = select_codes(num);
|
|
|
// auto src = select_codes(num);
|
|
@ -116,6 +85,20 @@ std::vector<std::string> str_common_codes(uint64_t num, bool shorten) { |
|
|
return codes; |
|
|
return codes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> str_short_codes(uint64_t num) { |
|
|
|
|
|
|
|
|
|
|
|
auto src = short_code_samples(num); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> codes; |
|
|
|
|
|
|
|
|
|
|
|
codes.reserve(src.size()); |
|
|
|
|
|
for (auto x : src) { |
|
|
|
|
|
codes.emplace_back(klotski::codec::ShortCode::unsafe_create(x).to_string()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return codes; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void CommonCodeSerialize(benchmark::State &state) { |
|
|
static void CommonCodeSerialize(benchmark::State &state) { |
|
|
|
|
|
|
|
|
// common_code_samples(8);
|
|
|
// common_code_samples(8);
|
|
@ -174,10 +157,48 @@ static void CommonCodeDeserializeShorten(benchmark::State &state) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BENCHMARK(CommonCodeSerialize)->Range(8, 256); |
|
|
static void ShortCodeSerialize(benchmark::State &state) { |
|
|
BENCHMARK(CommonCodeDeserialize)->Range(8, 256); |
|
|
std::vector<uint32_t> samples = short_code_samples(state.range(0)); |
|
|
BENCHMARK(CommonCodeSerializeShorten)->Range(8, 256); |
|
|
|
|
|
BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256); |
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
|
|
|
|
for (const auto code : samples) { |
|
|
|
|
|
volatile auto ret = klotski::codec::ShortCode::string_encode(code); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.SetItemsProcessed(state.iterations() * state.range(0)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ShortCodeDeserialize(benchmark::State &state) { |
|
|
|
|
|
|
|
|
|
|
|
const auto tmp = str_short_codes(state.range(0)); |
|
|
|
|
|
|
|
|
|
|
|
const std::vector<std::string_view> samples {tmp.begin(), tmp.end()}; |
|
|
|
|
|
|
|
|
|
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
|
|
|
|
for (const auto code : samples) { |
|
|
|
|
|
|
|
|
|
|
|
volatile auto ret = klotski::codec::ShortCode::string_decode(code); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.SetItemsProcessed(state.iterations() * state.range(0)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// BENCHMARK(CommonCodeSerialize)->Range(8, 256);
|
|
|
|
|
|
// BENCHMARK(CommonCodeDeserialize)->Range(8, 256);
|
|
|
|
|
|
// BENCHMARK(CommonCodeSerializeShorten)->Range(8, 256);
|
|
|
|
|
|
// BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256);
|
|
|
|
|
|
|
|
|
|
|
|
BENCHMARK(ShortCodeSerialize)->Range(8, 256); |
|
|
|
|
|
BENCHMARK(ShortCodeDeserialize)->Range(8, 256); |
|
|
|
|
|
|
|
|
// static void CommonCodeDecode(benchmark::State &state) {
|
|
|
// static void CommonCodeDecode(benchmark::State &state) {
|
|
|
// const auto tmp = str_common_codes(state.range(0));
|
|
|
// const auto tmp = str_common_codes(state.range(0));
|
|
|