Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <stdint.h>
  5.  
  6. // Math_random returns 0 or 1
  7. const int RAND_MID = RAND_MAX / 2;
  8. int8_t Math_random() {
  9.     return rand() >= RAND_MID;
  10. }
  11.  
  12. const int size = 200;
  13. const int sizeX = 512;
  14. const int sizeY = 512;
  15.  
  16. void test() {
  17.     int8_t t[size][sizeX];
  18.     // array t fills from local storage
  19.     for(int n = 0; n < size; n++) {
  20.         for(int i = 0; i < sizeX; i++)
  21.             t[n][i] = Math_random();
  22.     }
  23.     // array t fills from local storage
  24.    
  25.     for(int n = 0; n < size; n++) {
  26.         int8_t array[sizeX][sizeY];
  27.  
  28.         for(int x = 0; x < sizeX; x++) {
  29.             for(int y = 0; y < sizeY; y++) {
  30.                 array[x][y] = Math_random();
  31.             }
  32.         }
  33.        
  34.         int xp, yp, xm, ym, q;
  35.         for(int i = 0; i < 100; i++) {
  36.  
  37.             int8_t temp[sizeX][sizeY];
  38.             for (int x = 0; x < sizeX; x++) {
  39.                 xm = x - 1;
  40.                 if (xm == -1) xm = sizeX - 1;
  41.                 xp = x + 1;
  42.                 if (xp == sizeX) xp = 0;
  43.  
  44.                 for(int y = 0; y < sizeY; y++){
  45.                     ym = y - 1;
  46.                     if (ym == -1) ym = sizeY - 1;
  47.                     yp = y + 1;
  48.                     if (yp == sizeY) yp = 0;
  49.                    
  50.                     q = array[xm][ym];
  51.                     q = (q << 1) + array[x][ym];
  52.                     q = (q << 1) + array[xp][ym];
  53.                     q = (q << 1) + array[xm][y];
  54.                     q = (q << 1) + array[x][y];
  55.                     q = (q << 1) + array[xp][y];
  56.                     q = (q << 1) + array[xm][yp];
  57.                     q = (q << 1) + array[x][yp];
  58.                     q = (q << 1) + array[xp][yp];
  59.                    
  60.                     temp[x][y] = t[n][q];
  61.                 }
  62.             }
  63.  
  64.             for (int x = 0; x < sizeX; x++) {
  65.                 for (int y = 0; y < sizeY; y++) {
  66.                     array[x][y] = temp[x][y];
  67.                 }
  68.             }
  69.  
  70.         }
  71.         printf("%d\n", (int)array[0][0]);
  72.     }
  73. }
  74.  
  75.  
  76. int main(int argc, char ** argv) {
  77.     srand(time(NULL));
  78.  
  79.     long start = time(NULL);
  80.     test();
  81.     long end = time(NULL);
  82.     printf("%ld\n", end - start);
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement