fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <set>
  4. #include <chrono>
  5. #include <random>
  6. using namespace std;
  7. using namespace std::chrono;
  8. auto prng = default_random_engine(random_device()());
  9. uniform_int_distribution<int> dist(0, 4000);
  10. int main()
  11. {
  12. vector<int> vec;
  13. for (int i = 0; i < 4000; i++)
  14. vec.emplace_back(dist(prng));
  15.  
  16. steady_clock::time_point stamp;
  17.  
  18. unordered_set<int> set1(4000);
  19.  
  20. stamp = steady_clock::now();
  21. for (auto e : vec)
  22. set1.emplace(e);
  23. cout << (steady_clock::now() - stamp).count() << endl;
  24.  
  25. stamp = steady_clock::now();
  26. for (auto e : vec)
  27. set1.erase(e);
  28. cout << (steady_clock::now() - stamp).count() << endl;
  29.  
  30. auto hash = [](int i) {return i; };
  31. unordered_set<int, decltype(hash)> set2(4000, hash);
  32.  
  33. stamp = steady_clock::now();
  34. for (auto e : vec)
  35. set2.emplace(e);
  36. cout << (steady_clock::now() - stamp).count() << endl;
  37.  
  38. stamp = steady_clock::now();
  39. for (auto e : vec)
  40. set2.erase(e);
  41. cout << (steady_clock::now() - stamp).count() << endl;
  42.  
  43. cin.get();
  44. return 0;
  45. }
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
390098
167162
347958
164002