Tools made in assistance of the Metacall Project
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

47 righe
1.2 KiB

3 anni fa
  1. #include "lfhmap.hpp"
  2. #include <string>
  3. #include <iostream>
  4. #include <future>
  5. #include <vector>
  6. template<typename fn>
  7. void repeat(size_t nb, fn v) {
  8. while(nb--) {
  9. v();
  10. }
  11. }
  12. int main() {
  13. constexpr size_t thread_cnt = 16;
  14. size_t v = 0;
  15. auto map = new mct20::lfhmap<size_t, std::string, 8000>();
  16. std::vector<std::future<int>> finals;
  17. auto start = std::chrono::high_resolution_clock::now();
  18. repeat(thread_cnt, [&](){
  19. size_t v2 = v;
  20. v++;
  21. finals.push_back(std::async(std::launch::async, [&map, v2](){
  22. for(int a = v2; a < 250000; a+=thread_cnt) {
  23. map->set(a, std::to_string(a));
  24. }
  25. for(int a = v2; a < 250000; a+=thread_cnt) {
  26. if(auto acc = map->get(a); acc) {
  27. const std::string& t = acc.value();
  28. if(t != std::to_string(a))
  29. return 1;
  30. } else
  31. return 1;
  32. }
  33. return 0;
  34. }));
  35. });
  36. for(auto& a : finals) a.wait();
  37. int ret = 0;
  38. for(auto& a : finals) ret += a.get();
  39. auto time = std::chrono::high_resolution_clock::now() - start;
  40. std::cout << "Test 06 took " << std::chrono::duration_cast<std::chrono::milliseconds>(time).count() << "ms" << std::endl;
  41. std::cout << "Per 1R1W ("<< thread_cnt << " threads) " << std::chrono::duration_cast<std::chrono::nanoseconds>(time).count()/250000 << "ns" << std::endl;
  42. return ret;
  43. }