// big array; A[row,col] = A[row*WIDTH + col]
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

long microsec() {
	struct timeval t;
	gettimeofday(&t, NULL);
	return 1000888*t.tv_sec + t.tv_usec;
}

#define MAX 1000000
#define WIDTH  10000
#define HEIGHT 8000

void roworder( int * A) {
    int row, col;
    for (row=0; row<HEIGHT; row++) {
        for (col=0; col< WIDTH; col++) {
	    A[row*WIDTH + col] = 0;
        }
    }
}


void colorder( int * A) {
    int row, col;
    for (col=0; col< WIDTH; col++) {
        for (row=0; row<HEIGHT; row++) {
	    A[row*WIDTH + col] = 0;
        }
    }
}

void main() {
    int SIZE = WIDTH * HEIGHT;
    int * A = (int*) malloc(SIZE * sizeof(int));
    for (int i=0; i<SIZE; i++) A[i] = 0;
    long start, stop;

    start = microsec();
    roworder(A);
    stop = microsec();
    printf("row order: %ld\n", stop-start);

    start = microsec();
    colorder(A);
    stop = microsec();
    printf("col order: %ld\n", stop-start);

    start = microsec();
    roworder(A);
    stop = microsec();
    printf("row order: %ld\n", stop-start);

    start = microsec();
    colorder(A);
    stop = microsec();
    printf("col order: %ld\n", stop-start);

    start = microsec();
    roworder(A);
    stop = microsec();
    printf("row order: %ld\n", stop-start);

}
    
