測試的數據是以arm-eabi-g++來編譯,後來有試過改成可以讓arm-eabi-gcc來編譯的版本,測試結果其實差不多。以下是測試的程式及環境
- 測試程式
#include <sys/time.h> #include <math.h> #include <stdio.h> #include <stdlib.h> using namespace std; long double timer[10]; int matrix_size; /*Timer*/ long double high_prec_time(){ timeval tv; gettimeofday(&tv,0); return (long double)tv.tv_sec+tv.tv_usec*1e-6; } void set_timer(int k=0){ timer[k]=high_prec_time(); } double get_timer(int k=0){ return (double)(high_prec_time()-timer[k]); } /*Matrix Mul*/ template <class T> void _matrix_mul(T *matrixA,T *matrixC){ T tmpA; for(int i=0;i<matrix_size;i++){ for(int j=0;j<matrix_size;j++){ for(int k=0;k<matrix_size;k++){ tmpA=*(matrixA+k*matrix_size+j); //cout<<tmpA<<endl; *(matrixC+(i*matrix_size+j)) += tmpA*tmpA; } } } } void int_matrix_mul(int matrix_size){ int matrixA[matrix_size][matrix_size]; int matrixC[matrix_size][matrix_size]; //srand(time(0)); for(int i=0;i<matrix_size;i++){ for(int j=0;j<matrix_size;j++){ matrixA[i][j]=rand()%RAND_MAX; //cout<<matrixA[i][j]<<RAND_MAX<<endl; matrixC[i][j]=0; } } _matrix_mul(&matrixA[0][0],&matrixC[0][0]); } void float_matrix_mul(int matrix_size){ float matrixA[matrix_size][matrix_size]; float matrixC[matrix_size][matrix_size]; //srand(time(0)); for(int i=0;i<matrix_size;i++){ for(int j=0;j<matrix_size;j++){ matrixA[i][j]=(float)(rand()%RAND_MAX); matrixC[i][j]=0; } } _matrix_mul(&matrixA[0][0],&matrixC[0][0]); } void double_matrix_mul(int matrix_size){ double matrixA[matrix_size][matrix_size]; double matrixC[matrix_size][matrix_size]; //srand(time(0)); for(int i=0;i<matrix_size;i++){ for(int j=0;j<matrix_size;j++){ matrixA[i][j]=(double)(rand()%RAND_MAX); matrixC[i][j]=0; } } _matrix_mul(&matrixA[0][0],&matrixC[0][0]); } int main(){ matrix_size=512; set_timer(0); int_matrix_mul(matrix_size); printf("Integer Matrix Mul spend time: %f",get_timer(0)); set_timer(0); float_matrix_mul(matrix_size); printf("Float Matrix Mul spend time: %f",get_timer(0)); set_timer(0); double_matrix_mul(matrix_size); printf("Double Matrix Mul spend time: %f",get_timer(0)); }
- 硬體:
- SOC: TEGRA3
- RAM: 1G
- 軟體:
- ICS 4.0.4
- GCC: arm-eabi-g++ 4.4.3
沒有留言:
張貼留言