Advertisement
Guest User

vector<bool> is EVIL

a guest
Dec 17th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<vector>
  3. #include<time.h>
  4. using namespace std;
  5.  
  6. vector<bool> bools;
  7. vector<char> chars;
  8.  
  9. const int N=10000000;
  10.  
  11. void test_chars()
  12. {
  13.     chars.clear();
  14.     double start=clock();
  15.     char tmp=0;
  16.     for(int i=0;i<N;++i)
  17.     {
  18.         chars.push_back((char)(i%2));
  19.     }
  20.     for(int i=0;i<N;++i)
  21.     {
  22.         chars[i],chars[i],chars[i];
  23.     }
  24.     printf("chars: %.4lf\n",(clock()-start)/CLOCKS_PER_SEC);
  25. }
  26. void test_bools()
  27. {
  28.     bools.clear();
  29.     double start=clock();
  30.     for(int i=0;i<N;++i)
  31.     {
  32.         bools.push_back((bool)(i%2));
  33.     }
  34.     for(int i=0;i<N;++i)
  35.     {
  36.         bools[i],bools[i],bools[i];
  37.     }
  38.     printf("bools: %.4lf\n",(clock()-start)/CLOCKS_PER_SEC);
  39. }
  40.  
  41. const bool D=1;
  42. int main()
  43. {
  44.     for(int i=0;i<5;++i)
  45.     {
  46.         test_chars();
  47.         test_bools();
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement