本文介绍了使用QueryPerformanceCounter进行代码计时,为什么输出T和D失真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
void getTranspose(int C[4][4], int T[4][4])
{
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
T[i][j]=C[j][i];
}
void MatrixMultiply_CX(int C[4][4], int X[4][4],int R[4][4])
{
cout << endl;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++) R[i][j]=0;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
for (int k=0;k<4;k++)
R[i][j] +=C[i][k]*X[k][j];// Product formula
}
void MatrixMultiply_RT(int R[4][4], int T[4][4],int D[4][4])
{
cout << endl;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++) D[i][j]=0;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
for (int k=0;k<4;k++)
D[i][j] +=R[i][k]*T[k][j];
}
void main(void)
{
int C[4][4] ={1,1,1,1,2,1,-1,-2,1,-1,-1,1,1,-2,2,-1};
int X[4][4] ={4,8,6,9,7,6,3,11,1,9,8,3,15,5,15,6};
int R[4][4];
int T[4][4];
int D[4][4];
UINT64 startCount, endCount, diffCount, freq;
QueryPerformanceCounter((LARGE_INTEGER*)&startCount);
QueryPerformanceCounter((LARGE_INTEGER*)&endCount);
for (int i=0;i<4;i++) {
for (int j=0;j<4;j++)cout << T[i][j] << " ";
cout << endl;
}
MatrixMultiply_CX(C, X, R);
for(int i = 0; i<4; i++){
for(int j = 0; j<4; j++)cout << R[i][j] << " ";
cout << endl;
}
MatrixMultiply_RT(R, T, D);
for(int i = 0; i<4; i++){
for(int j = 0; j<4; j++) cout << D[i][j] << " ";
cout << endl;
}
diffCount = endCount - startCount;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
double exeTime_in_ms = (double)diffCount * 1000.0 / freq;
printf("Executing time : %fms\n", exeTime_in_ms);
}
推荐答案
这篇关于使用QueryPerformanceCounter进行代码计时,为什么输出T和D失真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!