Tools made in assistance of the Metacall Project
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

48 řádky
1.2 KiB

#include "lfhmap.hpp"
#include <string>
#include <iostream>
#include <future>
#include <vector>
template<typename fn>
void repeat(size_t nb, fn v) {
while(nb--) {
v();
}
}
int main() {
constexpr size_t thread_cnt = 16;
size_t v = 0;
auto map = new mct20::lfhmap<size_t, std::string, 8000>();
std::vector<std::future<int>> finals;
auto start = std::chrono::high_resolution_clock::now();
repeat(thread_cnt, [&](){
size_t v2 = v;
v++;
finals.push_back(std::async(std::launch::async, [&map, v2](){
for(int a = v2; a < 250000; a+=thread_cnt) {
map->set(a, std::to_string(a));
}
for(int a = v2; a < 250000; a+=thread_cnt) {
if(auto acc = map->get(a); acc) {
const std::string& t = acc.value();
if(t != std::to_string(a))
return 1;
} else
return 1;
}
return 0;
}));
});
for(auto& a : finals) a.wait();
int ret = 0;
for(auto& a : finals) ret += a.get();
auto time = std::chrono::high_resolution_clock::now() - start;
std::cout << "Test 06 took " << std::chrono::duration_cast<std::chrono::milliseconds>(time).count() << "ms" << std::endl;
std::cout << "Per 1R1W ("<< thread_cnt << " threads) " << std::chrono::duration_cast<std::chrono::nanoseconds>(time).count()/250000 << "ns" << std::endl;
return ret;
}