fork(1) download
  1. #include <iostream>
  2. #include <stack>
  3. #include <ctime>
  4. #include <vector>
  5.  
  6. std::stack<clock_t> tictoc_stack;
  7.  
  8. void tic() {
  9. tictoc_stack.push(clock());
  10. }
  11.  
  12. void toc() {
  13. std::cout << "Time elapsed: "
  14. << ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC
  15. << std::endl;
  16. tictoc_stack.pop();
  17. }
  18.  
  19. using namespace std;
  20.  
  21. int main() {
  22.  
  23. int sizes[] = {5, 10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000};
  24.  
  25. for (int k = 0; k < 12; ++k) {
  26.  
  27. int SIZE = sizes[k];
  28.  
  29. cout << "SIZE " << SIZE << endl;
  30.  
  31. vector<vector<int> > v(SIZE, std::vector<int>(SIZE));
  32.  
  33. tic();
  34.  
  35. for (int t = 0; t < 1000; ++t) {
  36.  
  37. for (int i = 0; i < SIZE; ++i) {
  38. for (int j = 0; j < SIZE; ++j) {
  39. v[i][j] = v[i][j] + 5;
  40. }
  41. }
  42.  
  43. }
  44.  
  45. toc();
  46.  
  47. vector<vector<int> > v3(SIZE, std::vector<int>(SIZE));
  48.  
  49.  
  50. tic();
  51.  
  52. for (int t = 0; t < 1000; ++t) {
  53.  
  54. for (int i = 0; i < SIZE; ++i) {
  55. for (int j = 0; j < SIZE; ++j) {
  56. v3[j][i] = v3[j][i] + 5;
  57. }
  58. }
  59.  
  60. }
  61.  
  62. toc();
  63.  
  64.  
  65.  
  66. }
  67. }
Time limit exceeded #stdin #stdout 5s 11256KB
stdin
Standard input is empty
stdout
SIZE 5
Time elapsed: 0.000101
Time elapsed: 8.4e-05
SIZE 10
Time elapsed: 0.000158
Time elapsed: 0.000303
SIZE 20
Time elapsed: 0.000523
Time elapsed: 0.001412
SIZE 30
Time elapsed: 0.000974
Time elapsed: 0.002152
SIZE 40
Time elapsed: 0.000641
Time elapsed: 0.002548
SIZE 50
Time elapsed: 0.000991
Time elapsed: 0.00389
SIZE 100
Time elapsed: 0.003606
Time elapsed: 0.014904
SIZE 200
Time elapsed: 0.02187
Time elapsed: 0.062554
SIZE 300
Time elapsed: 0.048869
Time elapsed: 0.172209
SIZE 400
Time elapsed: 0.102696
Time elapsed: 0.335542
SIZE 500
Time elapsed: 0.168545
Time elapsed: 0.541631
SIZE 1000
Time elapsed: 1.55956