Test_2

중첩된 메모리로의 이동(원본 메모리 주소 > 목적 메모리 주소)

모든 test코드엔 include 와 main함수 정의는 넣지 않았습니다.

모든 test코드엔 아래 내용을 포함합니다.

#define MOVE_LEN 1500
#define SHIFT_LEN 3
int loop_cnt = 100000;
char array[MOVE_LEN + SHIFT_LEN];
const char *orig_src = array + SHIFT_LEN;
char *orig_dest = array;

모든 테스트는 5번씩 진행하였고, 결과는 평균치입니다.


1. 1-byte씩 이동

  const char *src;
  char *dest;
  size_t move_len;
  while (loop_cnt--) {
    move_len = MOVE_LEN;
    src = orig_src;
    dest = orig_dest;
    while (move_len--)
      *dest++ = *src++;
  }

결과 :

  MT7621 : real 3.90s / user 3.90s / sys 0s
  CN6330 : real 5.20s / user 5.20s / sys 0s
  PC     : real 0.26s / user 0.26s / sys 0s

2. 2-bytes씩 이동

  const char *src;
  char *dest;
  size_t move_len, temp;
  while (loop_cnt--) {
    move_len = MOVE_LEN;
    src = orig_src;
    dest = orig_dest;
    if ((long)dest & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest++ = *csrc++;
      dest = cdest;
      src = csrc;
      move_len--;
    }
    temp = move_len >> 1;
    if (temp) {
      short *sdest = dest;
      const short *ssrc = src;
      temp--;
      do
        *sdest++ = *ssrc++;
      while (temp--);
      dest = sdest;
      src = ssrc;
    }
    if (move_len & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest = *csrc;
    }
  }

결과 :

  MT7621 : real 23.40s / user 8.60s / sys 14.80s
  CN6330 : real  2.90s / user 2.90s / sys 0s
  PC     : real  0.17s / user 0.17s / sys 0s

3. 4-byte씩 이동

  const char *src;
  char *dest;
  size_t move_len, temp;
  while (loop_cnt--) {
    move_len = MOVE_LEN;
    src = orig_src;
    dest = orig_dest;
    if ((long)dest & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest++ = *csrc++;
      dest = cdest;
      src = csrc;
      move_len--;
    }
    if (move_len > 2 && (long)dest & 2) {
      short *sdest = dest;
      const short *ssrc = src;
      *sdest++ = *ssrc++;
      dest = sdest;
      src = ssrc;
      move_len -= 2;
    }
    temp = move_len >> 2;
    if (temp) {
      int *idest = dest;
      const short *isrc = src;
      temp--;
      do
        *idest++ = *isrc++;
      while (temp--);
      dest = idest;
      src = isrc;
    }
    if (move_len & 2) {
      short *sdest = dest;
      const short *ssrc = src;
      *sdest++ = *ssrc++;
      dest = sdest;
      src = ssrc;
    }
    if (move_len & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest = *csrc;
    }
  }

결과 :

  MT7621 : real 11.60s / user 4.60s / sys 7.0s
  CN6330 : real  1.60s / user 1.60s / sys 0s
  PC     : real  0.08s / user 0.08s / sys 0s

4. 8-byte씩 이동

  const char *src;
  char *dest;
  size_t move_len, temp;
  while (loop_cnt--) {
    move_len = MOVE_LEN;
    src = orig_src;
    dest = orig_dest;
    if ((long)dest & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest++ = *csrc++;
      dest = cdest;
      src = csrc;
      move_len--;
    }
    if (move_len > 2 && (long)dest & 2) {
      short *sdest = dest;
      const short *ssrc = src;
      *sdest++ = *ssrc++;
      dest = sdest;
      src = ssrc;
      move_len -= 2;
    }
    if (move_len > 4 && (long)dest & 4) {
      int *idest = dest;
      const int *isrc = src;
      *idest++ = *isrc++;
      dest = idest;
      src = isrc;
      move_len -= 4;
    }
    temp = move_len >> 3;
    if (temp) {
      long long *ldest = dest;
      const long long *lsrc = src;
      temp--;
      do
        *ldest++ = *lsrc++;
      while (temp--);
      dest = ldest;
      src = lsrc;
    }
    if (move_len & 4) {
      int *idest = dest;
      const int *isrc = src;
      *idest++ = *isrc++;
      dest = idest;
      src = isrc;
    }
    if (move_len & 2) {
      short *sdest = dest;
      const short *ssrc = src;
      *sdest++ = *ssrc++;
      dest = sdest;
      src = ssrc;
    }
    if (move_len & 1) {
      char *cdest = dest;
      const char *csrc = src;
      *cdest = *csrc;
    }
  }

결과 :

  MT7621 : 테스트X
  CN6330 : real 0.90s / user 0.90s / sys 0s
  PC     : real 0.05s / user 0.05s / sys 0s

results matching ""

    No results matching ""