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];
25 case 15: to
[ 14] = from
[ 14];
26 case 14: to
[ 13] = from
[ 13];
27 case 13: to
[ 12] = from
[ 12];
28 case 12: to
[ 11] = from
[ 11];
29 case 11: to
[ 10] = from
[ 10];
30 case 10: to
[ 9] = from
[ 9];
31 case 9: to
[ 8] = from
[ 8];
32 case 8: to
[ 7] = from
[ 7];
33 case 7: to
[ 6] = from
[ 6];
34 case 6: to
[ 5] = from
[ 5];
35 case 5: to
[ 4] = from
[ 4];
36 case 4: to
[ 3] = from
[ 3];
37 case 3: to
[ 2] = from
[ 2];
38 case 2: to
[ 1] = from
[ 1];
39 case 1: to
[ 0] = from
[ 0];
41 default: return ACE_OS::memcpy (dest
, src
, n
);
53 case 0: smemcpy ((void*)buffer
, (void*)" THIS IS A TEST", size
); break;
54 case 1: ACE_OS::memcpy ((void*)buffer
, (void*)" THIS IS A TEST", size
); break;
59 namespace { enum { ITERATIONS
= 100000000 }; }
62 run_main (int, ACE_TCHAR
*[])
64 ACE_START_TEST (ACE_TEXT ("Memcpy_Test"));
66 //ACE_Time_Value start, now;
67 struct timeval start
, now
;
69 for (int i
= ITERATIONS
; i
> 0; --i
)
72 start
= ACE_High_Res_Timer::gettimeofday_hr ();
73 for (int j
= ITERATIONS
; j
> 0; --j
)
76 now
= ACE_High_Res_Timer::gettimeofday_hr ();
78 double fast
= 1000000 *(now
.tv_sec
- start
.tv_sec
) +
79 now
.tv_usec
- start
.tv_usec
;
81 ACE_TEXT ("%f uSec per iteration for fast version.\n"),
84 start
= ACE_High_Res_Timer::gettimeofday_hr ();
85 for (int k
= ITERATIONS
; k
> 0; --k
)
88 now
= ACE_High_Res_Timer::gettimeofday_hr ();
90 double slow
= 1000000 * (now
.tv_sec
-start
.tv_sec
) + now
.tv_usec
- start
.tv_usec
;
92 ACE_TEXT ("%f uSec per iteration for slow version.\n"),