1 //=============================================================================
3 * @file Memcpy_Test.cpp
5 * @author Mike Marinez <mmartinez@oci.com>
7 * This test compares the performance of ACE_OS::memcpy with
8 * that of smemcpy which unrolls the memcpy loop upto size = 16.
10 //=============================================================================
12 #include "ace/OS_NS_string.h"
13 #include "ace/High_Res_Timer.h"
15 #include "test_config.h"
18 smemcpy (void *dest
, const void *src
, const size_t n
)
20 unsigned char *to
= static_cast<unsigned char*> (dest
);
21 const unsigned char *from
= static_cast<const unsigned char*> (src
);
24 case 16: to
[ 15] = from
[ 15];
26 case 15: to
[ 14] = from
[ 14];
28 case 14: to
[ 13] = from
[ 13];
30 case 13: to
[ 12] = from
[ 12];
32 case 12: to
[ 11] = from
[ 11];
34 case 11: to
[ 10] = from
[ 10];
36 case 10: to
[ 9] = from
[ 9];
38 case 9: to
[ 8] = from
[ 8];
40 case 8: to
[ 7] = from
[ 7];
42 case 7: to
[ 6] = from
[ 6];
44 case 6: to
[ 5] = from
[ 5];
46 case 5: to
[ 4] = from
[ 4];
48 case 4: to
[ 3] = from
[ 3];
50 case 3: to
[ 2] = from
[ 2];
52 case 2: to
[ 1] = from
[ 1];
54 case 1: to
[ 0] = from
[ 0];
57 default: return ACE_OS::memcpy (dest
, src
, n
);
65 size_t const size
= 16;
69 case 0: smemcpy ((void*)buffer
, (void*)" THIS IS A TEST", size
); break;
70 case 1: ACE_OS::memcpy ((void*)buffer
, (void*)" THIS IS A TEST", size
); break;
75 namespace { enum { ITERATIONS
= 100000000 }; }
78 run_main (int, ACE_TCHAR
*[])
80 ACE_START_TEST (ACE_TEXT ("Memcpy_Test"));
82 //ACE_Time_Value start, now;
83 struct timeval start
, now
;
85 for (int i
= ITERATIONS
; i
> 0; --i
)
88 start
= ACE_High_Res_Timer::gettimeofday_hr ();
89 for (int j
= ITERATIONS
; j
> 0; --j
)
92 now
= ACE_High_Res_Timer::gettimeofday_hr ();
94 double fast
= 1000000 *(now
.tv_sec
- start
.tv_sec
) +
95 now
.tv_usec
- start
.tv_usec
;
97 ACE_TEXT ("%f uSec per iteration for fast version.\n"),
100 start
= ACE_High_Res_Timer::gettimeofday_hr ();
101 for (int k
= ITERATIONS
; k
> 0; --k
)
104 now
= ACE_High_Res_Timer::gettimeofday_hr ();
106 double slow
= 1000000 * (now
.tv_sec
-start
.tv_sec
) + now
.tv_usec
- start
.tv_usec
;
107 ACE_DEBUG ((LM_DEBUG
,
108 ACE_TEXT ("%f uSec per iteration for slow version.\n"),