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.

50 righe
1.3 KiB

  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, 40000>();
  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. for(int a = v2; a < 250000; a+=thread_cnt) {
  34. map->remove(a);
  35. }
  36. return 0;
  37. }));
  38. });
  39. for(auto& a : finals) a.wait();
  40. int ret = 0;
  41. for(auto& a : finals) ret += a.get();
  42. auto time = std::chrono::high_resolution_clock::now() - start;
  43. std::cout << "Test 08 took " << std::chrono::duration_cast<std::chrono::milliseconds>(time).count() << "ms" << std::endl;
  44. std::cout << "Per 1R1W1D ("<< thread_cnt << " threads) " << std::chrono::duration_cast<std::chrono::nanoseconds>(time).count()/250000 << "ns" << std::endl;
  45. return ret;
  46. }