fork(2) download
  1. #include <cstdio>
  2. #include <ctime>
  3.  
  4. template<class T> struct Vector
  5. {
  6. T *b, *e;
  7. Vector(size_t n) : b(new T[n]), e(b + n) { }
  8. T &operator[](size_t i) { return b[i]; }
  9. T &at(size_t i) { if (i >= e - b) { throw "invalid"; } return b[i]; }
  10. };
  11.  
  12. // #define at operator[] // Comment this out to enable bounds-checking
  13.  
  14. int main(int argc, char **argv)
  15. {
  16. Vector<size_t> v(1 << 16);
  17. for (size_t *p = v.b; p != v.e; ++p) { *p = 1; }
  18. clock_t begin = clock();
  19. for (int j = 0; j < 1 << 12; ++j)
  20. {
  21. for (size_t i = 8, n = v.e - v.b; i < n; ++i)
  22. {
  23. v.at(i) += v.at(i - 8);
  24. v.at(i) ^= v.at(i - 7);
  25. v.at(i) -= v.at(i - 6);
  26. v.at(i) ^= v.at(i - 5);
  27. v.at(i) += v.at(i - 4);
  28. v.at(i) ^= v.at(i - 3);
  29. v.at(i) -= v.at(i - 2);
  30. v.at(i) ^= v.at(i - 1);
  31. }
  32. }
  33. clock_t end = clock();
  34. fprintf(stderr, "%u\n", clock() - begin);
  35. }
  36.  
Success #stdin #stdout #stderr 2.1s 3552KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
2090000