1 | |
---|
2 | #if defined IMPL_STL |
---|
3 | #include <string> |
---|
4 | #include <iostream> |
---|
5 | #include <cstdio> |
---|
6 | using namespace std; |
---|
7 | |
---|
8 | #elif defined IMPL_CFA_HL_SHARE |
---|
9 | #define IMPL_CFA_HL |
---|
10 | |
---|
11 | #elif defined IMPL_CFA_LL_SHARE |
---|
12 | #define IMPL_CFA_LL |
---|
13 | |
---|
14 | #elif defined IMPL_CFA_HL_NOSHARE |
---|
15 | #define IMPL_CFA_HL |
---|
16 | #define CFA_NOSHARE |
---|
17 | |
---|
18 | #elif defined IMPL_CFA_LL_NOSHARE |
---|
19 | #define IMPL_CFA_LL |
---|
20 | #define CFA_NOSHARE |
---|
21 | |
---|
22 | #elif defined IMPL_BUHR94 |
---|
23 | #include <iostream> |
---|
24 | #include <cstdio> |
---|
25 | #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h" |
---|
26 | |
---|
27 | #else |
---|
28 | #error Bad IMPL_ |
---|
29 | #endif |
---|
30 | |
---|
31 | |
---|
32 | #if defined IMPL_CFA_HL |
---|
33 | #include <string.hfa> |
---|
34 | #elif defined IMPL_CFA_LL |
---|
35 | #include <string_res.hfa> |
---|
36 | #endif |
---|
37 | |
---|
38 | #if defined CFA_NOSHARE |
---|
39 | #include <string_sharectx.hfa> |
---|
40 | #define STRING_SHARING_CONTROL \ |
---|
41 | string_sharectx c = { NO_SHARING }; |
---|
42 | #else |
---|
43 | #define STRING_SHARING_CONTROL |
---|
44 | #endif |
---|
45 | |
---|
46 | |
---|
47 | #include <time.h> |
---|
48 | |
---|
49 | |
---|
50 | #if defined IMPL_STL || defined IMPL_BUHR94 |
---|
51 | #define PRINT(s) std::cout << s << std::endl |
---|
52 | #elif defined IMPL_CFA_HL || defined IMPL_CFA_LL |
---|
53 | #define PRINT(s) sout | s; |
---|
54 | #else |
---|
55 | #error Unhandled print case |
---|
56 | #endif |
---|
57 | |
---|
58 | volatile int checkthis = 0; |
---|
59 | #define MAYBE( op ) if (checkthis) { op; } |
---|
60 | |
---|
61 | int main( int argc, char ** argv ) { |
---|
62 | |
---|
63 | STRING_SHARING_CONTROL |
---|
64 | |
---|
65 | enum { NumConcats = 100, Times = 5000000 }; |
---|
66 | clock_t start, end; |
---|
67 | |
---|
68 | int corpuslen = argc - 1; |
---|
69 | char ** corpus = argv + 1; |
---|
70 | |
---|
71 | #if defined IMPL_CFA_LL |
---|
72 | string_res x = "foo2"; |
---|
73 | string_res y; |
---|
74 | string_res z; |
---|
75 | #define RESET y = x; |
---|
76 | #else |
---|
77 | string x = "foo2"; |
---|
78 | string y; |
---|
79 | #define RESET y = x; |
---|
80 | #endif |
---|
81 | |
---|
82 | start = clock(); |
---|
83 | for ( volatile unsigned int t = 0; t < Times; t += 1 ) { |
---|
84 | RESET |
---|
85 | for ( volatile unsigned int i = 0; i < NumConcats; i += 1 ) { |
---|
86 | MAYBE( PRINT(y) ) |
---|
87 | char *toAppend = corpus[i%corpuslen]; |
---|
88 | #if defined OP_PLUS_THEN_ASSIGN && defined IMPL_CFA_LL |
---|
89 | z = y; |
---|
90 | z += toAppend; |
---|
91 | y = z; |
---|
92 | #elif defined OP_PLUS_THEN_ASSIGN |
---|
93 | y = y + toAppend; |
---|
94 | #elif defined OP_PLUSEQ |
---|
95 | y += toAppend; |
---|
96 | #endif |
---|
97 | } |
---|
98 | } |
---|
99 | end = clock(); |
---|
100 | double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; |
---|
101 | printf("%f sec\n", elapsed); |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|