Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <stdio.h>
#include <ctime>
#define NUMBER 10000

using namespace std;

double diffclock(clock_t clock1,clock_t clock2)
{
 double diffticks=clock1-clock2;
 double diffms=(diffticks*10)/CLOCKS_PER_SEC;
 return diffms;
}


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];

}

int main()
{
    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];

clock_t begin=clock();
    getTranspose(C, T);
    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;
    }

 clock_t end=clock();
 cout<<"Execution time: "<<diffclock(end,begin)<<" ms."<<endl;

    system ("PAUSE");
    return EXIT_SUCCESS;
}
Posted
Updated 5-Apr-10 23:23pm
v3

A splitting example :)

The "Is-State" :
// main.cpp
#include "any.h"
 

int takeFive()
{
  return 5;
}

int main()
{
  return takeFive();
}


The "Could/Should-State" :
// Five.h
#pragma once
// declaration:
int takeFive();
// Five.cpp
#include "Five.h"
// implementation: 
int takeFive()
{
  return 5;
}
// Main.cpp
#include "any.h"
#include "Five.h"
 

int main()
{
  return takeFive();
}

Now your project must contain
the both files: Five.cpp and Main.cpp -
to be compiled and linked correctly :)
 
Share this answer
 
Check if the high-resolution performance counter functions
C++
QueryPerformanceFrequency()
and
C++
QueryPerformanceCounter()
helps.

http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900