Advertisement
RobertDeMilo

RB2.3 Разработка своего профайлера

Apr 15th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <set>
  5. #include <chrono>
  6.  
  7. using namespace std;
  8. using namespace std::chrono;
  9.  
  10. class LogDuration
  11. {
  12. public:
  13.     explicit LogDuration(const string& msg = "") : message(msg + ": "), start(steady_clock::now())
  14.     {
  15.  
  16.     }
  17.     ~LogDuration()
  18.     {
  19.         auto finish = steady_clock::now();
  20.         auto dur = finish - start;
  21.         cerr << message << duration_cast<milliseconds>(dur).count() << " ms" << endl;
  22.     }
  23. private:
  24.     string message;
  25.     steady_clock::time_point start;
  26. };
  27.  
  28.  
  29. int main()
  30. {
  31.     LogDuration total("Total");
  32.  
  33.     ifstream in("input.txt");
  34.     int element_count;
  35.     in >> element_count;
  36.  
  37.     set<int> elements;
  38.     /*auto start = steady_clock::now();*/
  39.     {
  40.         LogDuration input("Input");
  41.         for (int i = 0; i < element_count; ++i)
  42.         {
  43.             int x;
  44.             in >> x;
  45.             elements.insert(x);
  46.         }
  47.     }
  48.     /*auto finish = steady_clock::now();
  49.     auto dur = finish - start;
  50.     cerr << duration_cast<milliseconds>(dur).count() << " ms" << endl;*/
  51.  
  52.     int query_count;
  53.     in >> query_count;
  54.  
  55.     int total_found = 0;
  56.  
  57.     {
  58.         LogDuration queries("Queries processing");
  59.         for (int i = 0; i < query_count; ++i)
  60.         {
  61.             int x;
  62.             in >> x;
  63.  
  64.             if (elements.find(x) != elements.end())
  65.             {
  66.                 ++total_found;
  67.             }
  68.         }
  69.     }
  70.  
  71.     cout << total_found << endl;
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement