C: memcpy speed on dynamically allocated arrays

后端 未结 3 1065
死守一世寂寞
死守一世寂寞 2021-02-13 17:17

I need help with the performance of the following code. It does a memcpy on two dynamically allocated arrays of arbitrary size:

int main()
{
  double *a, *b;
  u         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 17:32

    Surely if you are comparing the speed of initialise and copy to the speed of just copy, then the initialisation should be included in timed section. It appears to me you should actually be comparing this:

    // Version 1
    for(i=0; i

    To this:

    // Version 2
    for(i=0; i

    I expect this will see your 3x speed improvement drop sharply.

    EDIT: As suggested by Steve Jessop, you may also want to test a third strategy of only touching one entry per page:

    // Version 3
    for(i=0; i

提交回复
热议问题