Click here to Skip to main content
15,923,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Slow access to array Pin
Rage_bla9-Oct-05 3:58
Rage_bla9-Oct-05 3:58 
GeneralRe: Slow access to array Pin
rudo329-Oct-05 5:41
rudo329-Oct-05 5:41 
GeneralRe: Slow access to array Pin
Rage_bla9-Oct-05 5:54
Rage_bla9-Oct-05 5:54 
AnswerRe: Slow access to array Pin
John R. Shaw8-Oct-05 21:20
John R. Shaw8-Oct-05 21:20 
GeneralRe: Slow access to array Pin
rudo329-Oct-05 0:26
rudo329-Oct-05 0:26 
GeneralRe: Slow access to array Pin
John R. Shaw9-Oct-05 0:54
John R. Shaw9-Oct-05 0:54 
GeneralRe: Slow access to array Pin
rudo329-Oct-05 3:08
rudo329-Oct-05 3:08 
GeneralRe: Slow access to array Pin
John R. Shaw12-Oct-05 11:18
John R. Shaw12-Oct-05 11:18 
Sorry!Blush | :O It was way passed my bed time, you did provide enough imformation.

The order in which the calculation are done matters:
(VC6.0, optimizations: maximum speed, Compiled for release)
#define MATRIX_SIZE 1000
int M1[MATRIX_SIZE];
int M2[MATRIX_SIZE];
int M3[MATRIX_SIZE];
/////////////////////////////////
void matrix_speed_test() // AVARAGE TIME: 2.16 seconds
{
    int j, i, k;
    for( j=0;j<MATRIX_SIZE;++j )
    for( i=0;i<MATRIX_SIZE;++i )
    for( k=0;k<MATRIX_SIZE;++k )
        M3[j] = M1[i] * M2[k];
}

/////////////////////////////////
void matrix_speed_test2() // AVARAGE TIME: 0.61 seconds
{
    int j, i, k;
    int m1,m2;
    for( j=0;j<MATRIX_SIZE;++j )
    {
        m1 = M1[j];
        for( i=0;i<MATRIX_SIZE;++i )
        {
            m2 = M2[i];
            for( k=0;k<MATRIX_SIZE;++k ) 
                M3[k] = m1 * m2;
        }
    }
}

/////////////////////////////////
void matrix_speed_test3() // AVARAGE TIME: 1.91 seconds
{
    int j, i, k;
    int m1;
    for( j=0;j<MATRIX_SIZE;++j )
    {
        for( i=0;i<MATRIX_SIZE;++i )
        {
            m1 = M1[i];
            for( k=0;k<MATRIX_SIZE;++k ) 
                M3[j] = m1 * M2[k];
        }
    }
}

As you can see, rearanging the code to change where the indexing occurs can greatly increase the speed.

I tried a few other ways, but they still avaraged 2.17 seconds.

I hope that helps!

P.S. Sorry for the delay, I am usualy only online when reasearching.

INTP
Every thing is relative...
QuestionFree C++ .Net compiler questions Pin
Jim Crafton8-Oct-05 9:11
Jim Crafton8-Oct-05 9:11 
AnswerRe: Free C++ .Net compiler questions Pin
John R. Shaw8-Oct-05 23:11
John R. Shaw8-Oct-05 23:11 
GeneralRe: Free C++ .Net compiler questions Pin
Jim Crafton9-Oct-05 4:56
Jim Crafton9-Oct-05 4:56 
QuestionModeless dialog communicating with parent dialog Pin
fjlv20058-Oct-05 9:08
fjlv20058-Oct-05 9:08 
AnswerRe: Modeless dialog communicating with parent dialog Pin
Jose Lamas Rios8-Oct-05 14:32
Jose Lamas Rios8-Oct-05 14:32 
QuestionRe: Modeless dialog communicating with parent dialog Pin
fjlv20059-Oct-05 18:42
fjlv20059-Oct-05 18:42 
QuestionHow in CEdit to install the cursor in anchor point? Pin
pup20028-Oct-05 7:36
pup20028-Oct-05 7:36 
AnswerRe: How in CEdit to install the cursor in anchor point? Pin
Mircea Puiu8-Oct-05 21:03
Mircea Puiu8-Oct-05 21:03 
AnswerRe: How in CEdit to install the cursor in anchor point? Pin
John R. Shaw8-Oct-05 21:39
John R. Shaw8-Oct-05 21:39 
QuestionCButton with Bitmap Transparency Pin
fjlv20058-Oct-05 5:02
fjlv20058-Oct-05 5:02 
AnswerRe: CButton with Bitmap Transparency Pin
Lane Yu8-Oct-05 8:24
Lane Yu8-Oct-05 8:24 
QuestionRe: CButton with Bitmap Transparency Pin
fjlv20058-Oct-05 9:14
fjlv20058-Oct-05 9:14 
AnswerRe: CButton with Bitmap Transparency Pin
PJ Arends8-Oct-05 18:23
professionalPJ Arends8-Oct-05 18:23 
AnswerRe: CButton with Bitmap Transparency Pin
Lane Yu8-Oct-05 18:46
Lane Yu8-Oct-05 18:46 
Questionuse of extern keyword Pin
swaapu8-Oct-05 2:46
swaapu8-Oct-05 2:46 
AnswerRe: use of extern keyword Pin
G Haranadh8-Oct-05 3:08
G Haranadh8-Oct-05 3:08 
AnswerRe: use of extern keyword Pin
Bob Stanneveld8-Oct-05 7:02
Bob Stanneveld8-Oct-05 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.