#include <time.h>
#include <iostream>
#define SAMPLES 1000
#define MATSIZE 513
int mat[MATSIZE][MATSIZE];
void transpose()
{
for ( int i = 0 ; i < MATSIZE ; i++ )
for ( int j = 0 ; j < MATSIZE ; j++ )
{
int aux = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = aux;
}
}
int main()
{
for ( int i = 0 ; i < MATSIZE ; i++ )
for ( int j = 0 ; j < MATSIZE ; j++ )
mat[i][j] = i+j;
int t = clock();
for ( int i = 0 ; i < SAMPLES ; i++ )
transpose();
int elapsed = clock() - t;
std::cout << "Average for a matrix of " << MATSIZE << ": " << (float)elapsed * 1000 /( SAMPLES*CLOCKS_PER_SEC);
}
I2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKI2RlZmluZSBTQU1QTEVTIDEwMDAKI2RlZmluZSBNQVRTSVpFIDUxMwppbnQgbWF0W01BVFNJWkVdW01BVFNJWkVdOwoKdm9pZCB0cmFuc3Bvc2UoKQp7CiAgIGZvciAoIGludCBpID0gMCA7IGkgPCBNQVRTSVpFIDsgaSsrICkKICAgZm9yICggaW50IGogPSAwIDsgaiA8IE1BVFNJWkUgOyBqKysgKQogICB7CiAgICAgICBpbnQgYXV4ID0gbWF0W2ldW2pdOwogICAgICAgbWF0W2ldW2pdID0gbWF0W2pdW2ldOwogICAgICAgbWF0W2pdW2ldID0gYXV4OwogICB9Cn0KCmludCBtYWluKCkKewogICBmb3IgKCBpbnQgaSA9IDAgOyBpIDwgTUFUU0laRSA7IGkrKyApCiAgIGZvciAoIGludCBqID0gMCA7IGogPCBNQVRTSVpFIDsgaisrICkKICAgICAgIG1hdFtpXVtqXSA9IGkrajsKICAgaW50IHQgPSBjbG9jaygpOwogICBmb3IgKCBpbnQgaSA9IDAgOyBpIDwgU0FNUExFUyA7IGkrKyApCiAgICAgICB0cmFuc3Bvc2UoKTsKICAgaW50IGVsYXBzZWQgPSBjbG9jaygpIC0gdDsKICAgc3RkOjpjb3V0IDw8ICJBdmVyYWdlIGZvciBhIG1hdHJpeCBvZiAiIDw8IE1BVFNJWkUgPDwgIjogIiA8PCAoZmxvYXQpZWxhcHNlZCAqIDEwMDAgLyggU0FNUExFUypDTE9DS1NfUEVSX1NFQyk7Cn0=