fork(6) download
  1. #include <time.h>
  2. #include <iostream>
  3.  
  4. #define SAMPLES 1000
  5. #define MATSIZE 513
  6. int mat[MATSIZE][MATSIZE];
  7.  
  8. void transpose()
  9. {
  10. for ( int i = 0 ; i < MATSIZE ; i++ )
  11. for ( int j = 0 ; j < MATSIZE ; j++ )
  12. {
  13. int aux = mat[i][j];
  14. mat[i][j] = mat[j][i];
  15. mat[j][i] = aux;
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. for ( int i = 0 ; i < MATSIZE ; i++ )
  22. for ( int j = 0 ; j < MATSIZE ; j++ )
  23. mat[i][j] = i+j;
  24. int t = clock();
  25. for ( int i = 0 ; i < SAMPLES ; i++ )
  26. transpose();
  27. int elapsed = clock() - t;
  28. std::cout << "Average for a matrix of " << MATSIZE << ": " << (float)elapsed * 1000 /( SAMPLES*CLOCKS_PER_SEC);
  29. }
Success #stdin #stdout 0.77s 3752KB
stdin
Standard input is empty
stdout
Average for a matrix of 513: 0.75