Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Memcpy_Test.cpp
blobeec4ddac8e23bcfd936ffdd7b63993545ab32d49
1 //=============================================================================
2 /**
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.
9 */
10 //=============================================================================
12 #include "ace/OS_NS_string.h"
13 #include "ace/High_Res_Timer.h"
15 #include "test_config.h"
17 void *
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);
22 // Unroll the loop...
23 switch (n) {
24 case 16: to[ 15] = from[ 15];
25 ACE_FALLTHROUGH;
26 case 15: to[ 14] = from[ 14];
27 ACE_FALLTHROUGH;
28 case 14: to[ 13] = from[ 13];
29 ACE_FALLTHROUGH;
30 case 13: to[ 12] = from[ 12];
31 ACE_FALLTHROUGH;
32 case 12: to[ 11] = from[ 11];
33 ACE_FALLTHROUGH;
34 case 11: to[ 10] = from[ 10];
35 ACE_FALLTHROUGH;
36 case 10: to[ 9] = from[ 9];
37 ACE_FALLTHROUGH;
38 case 9: to[ 8] = from[ 8];
39 ACE_FALLTHROUGH;
40 case 8: to[ 7] = from[ 7];
41 ACE_FALLTHROUGH;
42 case 7: to[ 6] = from[ 6];
43 ACE_FALLTHROUGH;
44 case 6: to[ 5] = from[ 5];
45 ACE_FALLTHROUGH;
46 case 5: to[ 4] = from[ 4];
47 ACE_FALLTHROUGH;
48 case 4: to[ 3] = from[ 3];
49 ACE_FALLTHROUGH;
50 case 3: to[ 2] = from[ 2];
51 ACE_FALLTHROUGH;
52 case 2: to[ 1] = from[ 1];
53 ACE_FALLTHROUGH;
54 case 1: to[ 0] = from[ 0];
55 ACE_FALLTHROUGH;
56 case 0: return dest;
57 default: return ACE_OS::memcpy (dest, src, n);
61 void
62 testit (int type)
64 char buffer[16];
65 size_t const size = 16;
67 switch (type)
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 }; }
77 int
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)
86 testit (0);
88 start = ACE_High_Res_Timer::gettimeofday_hr ();
89 for (int j = ITERATIONS; j > 0; --j)
90 testit (0);
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;
96 ACE_DEBUG ((LM_DEBUG,
97 ACE_TEXT ("%f uSec per iteration for fast version.\n"),
98 fast / ITERATIONS));
100 start = ACE_High_Res_Timer::gettimeofday_hr ();
101 for (int k = ITERATIONS; k > 0; --k)
102 testit (1);
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"),
109 slow / ITERATIONS));
111 ACE_END_TEST;
113 return 0;