Advertisement
Guest User

GCC_Speed_test

a guest
Aug 24th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. class obj
  6. {
  7. public:
  8.   obj():v_(10000){}
  9.   obj(const obj&o):a_(o.a_),v_(o.v_){}
  10.   void set(int a){a_=a;}
  11.   int get() const {return a_;}
  12. private:
  13.   int a_;
  14.   std::vector<int> v_;
  15. };
  16.  
  17. inline bool asc(const obj& a, const obj& b)
  18. {
  19.   return (a.get()<b.get());
  20. }
  21.  
  22. inline  bool desc(const obj& a, const obj& b)
  23. {
  24.   return (a.get()>b.get());
  25. }
  26.  
  27. int main()
  28. {
  29.   const size_t size=10000;
  30.   std::vector<obj> v(size);
  31.  
  32.   for (int i=0; i<size; ++i)
  33.     v[i].set(i);
  34.  
  35.   for (int i=0; i<20; i++)
  36.     {
  37.       std::sort(v.begin(),v.end(),asc);
  38.       std::sort(v.begin(),v.end(),desc);
  39.     }
  40.  
  41.   return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement