Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <stdint.h>
- // Math_random returns 0 or 1
- const int RAND_MID = RAND_MAX / 2;
- int8_t Math_random() {
- return rand() >= RAND_MID;
- }
- const int size = 200;
- const int sizeX = 512;
- const int sizeY = 512;
- void test() {
- int8_t t[size][sizeX];
- // array t fills from local storage
- for(int n = 0; n < size; n++) {
- for(int i = 0; i < sizeX; i++)
- t[n][i] = Math_random();
- }
- // array t fills from local storage
- for(int n = 0; n < size; n++) {
- int8_t array[sizeX][sizeY];
- for(int x = 0; x < sizeX; x++) {
- for(int y = 0; y < sizeY; y++) {
- array[x][y] = Math_random();
- }
- }
- int xp, yp, xm, ym, q;
- for(int i = 0; i < 100; i++) {
- int8_t temp[sizeX][sizeY];
- for (int x = 0; x < sizeX; x++) {
- xm = x - 1;
- if (xm == -1) xm = sizeX - 1;
- xp = x + 1;
- if (xp == sizeX) xp = 0;
- for(int y = 0; y < sizeY; y++){
- ym = y - 1;
- if (ym == -1) ym = sizeY - 1;
- yp = y + 1;
- if (yp == sizeY) yp = 0;
- q = array[xm][ym];
- q = (q << 1) + array[x][ym];
- q = (q << 1) + array[xp][ym];
- q = (q << 1) + array[xm][y];
- q = (q << 1) + array[x][y];
- q = (q << 1) + array[xp][y];
- q = (q << 1) + array[xm][yp];
- q = (q << 1) + array[x][yp];
- q = (q << 1) + array[xp][yp];
- temp[x][y] = t[n][q];
- }
- }
- for (int x = 0; x < sizeX; x++) {
- for (int y = 0; y < sizeY; y++) {
- array[x][y] = temp[x][y];
- }
- }
- }
- printf("%d\n", (int)array[0][0]);
- }
- }
- int main(int argc, char ** argv) {
- srand(time(NULL));
- long start = time(NULL);
- test();
- long end = time(NULL);
- printf("%ld\n", end - start);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement