Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <time.h>
  2. #include <algorithm>
  3. #include <random>
  4. #include <vector>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <unordered_map>
  9. #include <map>
  10. using namespace std;
  11.  
  12. int main() {
  13. ifstream file;
  14. file.open("words.txt");
  15. vector<string> v;
  16. v.reserve(10000);
  17. string x;
  18. while(file >> x)
  19. v.push_back(x);
  20. //random_shuffle(begin(v),end(v));
  21. unordered_map<string, int> umap;
  22. map<string, int> map;
  23. clock_t heildumap, heildmap, t;
  24. for(int i=0;i<v.size();i++){
  25. t=clock();
  26. umap[v[i]]=i;
  27. heildumap+=clock()-t;
  28. t=clock();
  29. map[v[i]]=i;
  30. heildmap+=clock()-t;
  31. }
  32. cout<< heildumap/v.size() << " " << heildmap/v.size() << endl;
  33. heildumap=0;
  34. heildmap=0;
  35. for(int i=0;i<v.size();i++){
  36. t=clock();
  37. umap.find(v[i]);
  38. heildumap+=clock()-t;
  39. t=clock();
  40. map.find(v[i]);
  41. heildmap+=clock()-t;
  42. }
  43. cout<< heildumap/v.size() << " " << heildmap/v.size()<< endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement