Advertisement
RobertDeMilo

RB2.4 Совершенствование своего профайлера

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