Browse Source

test: benchmark with diff `FC_MAP_RESERVE`

legacy
Dnomd343 2 years ago
parent
commit
b37eef4bf6
  1. 24
      src/fast_cal/cal_core.cc
  2. 2
      src/fast_cal/fast_cal.h
  3. 61
      src/main.cc

24
src/fast_cal/cal_core.cc

@ -44,11 +44,35 @@ void FastCal::build() {
}
}
#include <iostream>
/// found first matched target
RawCode FastCal::target(const match_t &match) {
auto core = init(root);
// std::cout << "-----------------------------------" << std::endl;
// std::cout << "start count: " << cases.bucket_count() << std::endl;
while (!cache.empty()) {
if (match(cache.front()->code)) {
// std::cout << "hashmap size: " << cases.size() << std::endl;
// std::cout << "bucket count: " << cases.bucket_count() << std::endl;
// std::cout << "load factor: " << cases.load_factor() << std::endl;
// std::vector<uint32_t> temp;
// for (uint32_t i = 0; i < cases.bucket_count(); ++i) {
// uint32_t size = cases.bucket_size(i);
// if (size >= temp.size()) {
// temp.resize(size + 1);
// }
// ++temp.at(size);
// }
// for (uint32_t i = 0; i < temp.size(); ++i) {
// std::cout << "size " << i << " -> " << temp[i] << std::endl;
// }
return RawCode::unsafe_create(cache.front()->code); // match target
}
core.next_cases(cache.front()->code, cache.front()->mask);

2
src/fast_cal/fast_cal.h

@ -8,7 +8,7 @@
#include "core.h"
#include "raw_code.h"
const uint32_t FC_MAP_RESERVE = 65536;
const uint32_t FC_MAP_RESERVE = 65536 * 8;
/// FastCal not found -> return invalid raw code
const RawCode FC_NOT_FOUND = RawCode::unsafe_create(0);

61
src/main.cc

@ -19,22 +19,22 @@ int main() {
// AllCases::build();
// std::vector<RawCode> test_cases;
// {
// AllCases::build();
// std::vector<uint64_t> all_cases;
// for (uint64_t head = 0; head < 16; ++head) {
// for (const auto &range : AllCases::fetch()[head]) {
// all_cases.emplace_back(head << 32 | range);
// }
// }
// for (uint32_t i = 0; i < 1000; ++i) {
// test_cases.emplace_back(
// RawCode::from_common_code(all_cases.at(i * 29334))
// );
// }
// }
// std::cout << "test size -> " << test_cases.size() << std::endl;
std::vector<RawCode> test_cases;
{
AllCases::build();
std::vector<uint64_t> all_cases;
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : AllCases::fetch()[head]) {
all_cases.emplace_back(head << 32 | range);
}
}
for (uint32_t i = 0; i < 100; ++i) {
test_cases.emplace_back(
RawCode::from_common_code(all_cases.at(i * 293344))
);
}
}
std::cout << "test size -> " << test_cases.size() << std::endl;
// std::cout << "wait 3s" << std::endl;
@ -44,25 +44,28 @@ int main() {
auto start_time = clock();
// {
// auto fc = FastCal(RawCode::unsafe_create(0));
// for (auto code : test_cases) {
// fc.set_root(code);
// auto fc = FastCal(RawCode::from_common_code("1a9bf0c"));
// fc.solve();
// }
// }
{
auto fc = FastCal(RawCode::unsafe_create(0));
for (auto code : test_cases) {
fc.set_root(code);
fc.solve();
}
}
auto a = Analyse(RawCode::from_common_code("1a9bf0c"));
// auto a = Analyse(RawCode::from_common_code("1a9bf0c"));
// a.build();
auto ret = a.build_until([](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
});
// auto ret = a.build_until([](uint64_t code) {
// return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
// });
// for (const auto &r : ret) {
// std::cout << r << std::endl;
// }
a.backtrack_demo(0x7F87E0E5BFFF492);
// a.backtrack_demo(0x7F87E0E5BFFF492);
// a.backtrack_demo(0x1FB1E36F9FFF492);
// auto start_time = clock();
@ -108,8 +111,8 @@ int main() {
// std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl;
// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
// std::cout << "complete benchmark" << std::endl;

Loading…
Cancel
Save