fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. const int H = 10000;
  5. const int W = 10000;
  6.  
  7. int main(int argc, char* argv[]) {
  8. int** table = (int**)malloc(H * sizeof(int*));
  9. for (int i = 0; i < H; ++i) {
  10. table[i] = (int*)malloc(W * sizeof(int));
  11. }
  12. for (int row = 0; row < H; ++row) {
  13. for (int col = 0; col < W; ++col) {
  14. table[row][col] = (col + 1) + W * row;
  15. }
  16. }
  17.  
  18. long total = 0;
  19.  
  20. if (argc == 1) {
  21. printf("access: for each row\n");
  22. for (int i = 0; i < 10; ++i) {
  23. for (int row = 0; row < 10000; ++row) {
  24. for (int col = 0; col < 10000; ++col) {
  25. total += table[row][col];
  26. }
  27. }
  28. }
  29. } else {
  30. printf("access: for each column\n");
  31. for (int i = 0; i < 10; ++i) {
  32. for (int col = 0; col < 10000; ++col) {
  33. for (int row = 0; row < 10000; ++row) {
  34. total += table[row][col];
  35. }
  36. }
  37. }
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.2s 392316KB
stdin
Standard input is empty
stdout
access: for each row