我想请求帮助测量下方矩阵乘法的执行时间。 我在 Windows 运行代码 。 我尝试使用 < a href=" http://www. cplusplus.com/ reference/clibrary/ ctime/ " relation="nofollow" >time. h < / a >, 但无法测量 。 我要将计时器放在哪里?
#include<stdio.h>
#include<math.h>
#include<time.h>
void main()
{
int m1[10][10],i,j,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
/*double dif;
time_t start, end;*/
printf("Enter number of rows and columns of first matrix MAX 10
");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of second matrix MAX 10
");
scanf("%d%d",&r2,&c2);
if(r2==c1)
{
printf("Enter rows and columns of First matrix
");
printf("Row wise
");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("You have entered the first matrix as follows:
");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d ",m1[i][j]);
printf("
");
}
printf("Enter rows and columns of Second matrix
");
printf("Again row wise
");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the second matrix as follows:
");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d ",m2[i][j]);
printf("
");
}
/*time (&start);*/
printf("Now we multiply both the above matrix
");
printf("The result of the multiplication is as follows:
");
/*a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32 a11xA13+a12xA23+a13xA33*/
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d ",mult[i][j]);
}
printf("
");
/*time (&end);
dif (difftime (end, start);
printf("Time of execution is : %f
",dif)*/
}
getch();
}
else
{
printf("Matrix multiplication cannot be done");
}
}
我希望测量尽可能准确