| [08ed947] | 1 | #if defined IMPL_STL_NA_NA
 | 
|---|
 | 2 |   #define IMPL_STL
 | 
|---|
 | 3 | #endif
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | #if defined IMPL_BUHR94_NA_NA
 | 
|---|
 | 6 |   #define IMPL_BUHR94
 | 
|---|
 | 7 | #endif
 | 
|---|
| [01db301] | 8 | 
 | 
|---|
 | 9 | #if defined IMPL_STL
 | 
|---|
 | 10 |   #include <string>
 | 
|---|
 | 11 |   #include <iostream>
 | 
|---|
 | 12 |   #include <cstdio>
 | 
|---|
 | 13 |   using namespace std;
 | 
|---|
| [4d0eb1c] | 14 |   #define IMPL_CXX
 | 
|---|
| [01db301] | 15 | 
 | 
|---|
 | 16 | #elif defined IMPL_CFA_HL_SHARE
 | 
|---|
 | 17 |   #define IMPL_CFA_HL
 | 
|---|
| [4d0eb1c] | 18 |   #define IMPL_CFA
 | 
|---|
| [01db301] | 19 | 
 | 
|---|
 | 20 | #elif defined IMPL_CFA_LL_SHARE
 | 
|---|
 | 21 |   #define IMPL_CFA_LL
 | 
|---|
| [4d0eb1c] | 22 |   #define IMPL_CFA
 | 
|---|
| [01db301] | 23 | 
 | 
|---|
 | 24 | #elif defined IMPL_CFA_HL_NOSHARE
 | 
|---|
 | 25 |   #define IMPL_CFA_HL
 | 
|---|
 | 26 |   #define CFA_NOSHARE
 | 
|---|
| [4d0eb1c] | 27 |   #define IMPL_CFA
 | 
|---|
| [01db301] | 28 | 
 | 
|---|
 | 29 | #elif defined IMPL_CFA_LL_NOSHARE
 | 
|---|
 | 30 |   #define IMPL_CFA_LL
 | 
|---|
 | 31 |   #define CFA_NOSHARE
 | 
|---|
| [4d0eb1c] | 32 |   #define IMPL_CFA
 | 
|---|
| [01db301] | 33 | 
 | 
|---|
 | 34 | #elif defined IMPL_BUHR94
 | 
|---|
 | 35 |   #include <iostream>
 | 
|---|
 | 36 |   #include <cstdio>
 | 
|---|
 | 37 |   #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
 | 
|---|
| [4d0eb1c] | 38 |   #define IMPL_CXX
 | 
|---|
| [01db301] | 39 | 
 | 
|---|
 | 40 | #else
 | 
|---|
 | 41 |   #error Bad IMPL_
 | 
|---|
 | 42 | #endif
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | #if defined IMPL_CFA_HL
 | 
|---|
 | 46 |   #include <string.hfa>
 | 
|---|
 | 47 | #elif defined IMPL_CFA_LL
 | 
|---|
 | 48 |   #include <string_res.hfa>
 | 
|---|
 | 49 | #endif
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | #if defined CFA_NOSHARE
 | 
|---|
 | 52 |   #include <string_sharectx.hfa>
 | 
|---|
 | 53 |   #define STRING_SHARING_CONTROL \
 | 
|---|
 | 54 |     string_sharectx c = { NO_SHARING };
 | 
|---|
 | 55 | #else 
 | 
|---|
 | 56 |   #define STRING_SHARING_CONTROL
 | 
|---|
 | 57 | #endif
 | 
|---|
 | 58 | 
 | 
|---|
| [4d0eb1c] | 59 | #if defined IMPL_CFA
 | 
|---|
 | 60 |   #include <math.hfa>
 | 
|---|
| [08ed947] | 61 |   extern "C" {
 | 
|---|
 | 62 |     void malloc_stats( void );
 | 
|---|
 | 63 |   }
 | 
|---|
| [4d0eb1c] | 64 | #elif defined IMPL_CXX
 | 
|---|
 | 65 |   #include <algorithm>
 | 
|---|
 | 66 |   using std::min;
 | 
|---|
| [08ed947] | 67 |   #include <malloc.h>
 | 
|---|
| [4d0eb1c] | 68 | #endif
 | 
|---|
| [01db301] | 69 | 
 | 
|---|
 | 70 | #include <time.h>
 | 
|---|
| [4d0eb1c] | 71 | #include <stdlib.h> // atoi
 | 
|---|
 | 72 | #include <string.h> // strlen, only during setup
 | 
|---|
| [01db301] | 73 | 
 | 
|---|
 | 74 | #if defined IMPL_STL || defined IMPL_BUHR94
 | 
|---|
 | 75 |     #define PRINT(s) std::cout << s << std::endl
 | 
|---|
 | 76 | #elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
 | 
|---|
 | 77 |     #define PRINT(s) sout | s;
 | 
|---|
 | 78 | #else
 | 
|---|
 | 79 |     #error Unhandled print case
 | 
|---|
 | 80 | #endif
 | 
|---|
 | 81 | 
 | 
|---|
| [4d0eb1c] | 82 | double meanLen(int N, char ** strings) {
 | 
|---|
 | 83 |     int totalLen = 0;
 | 
|---|
 | 84 |     for (int i = 0 ; i < N; i ++) {
 | 
|---|
 | 85 |         totalLen += strlen(strings[i]);
 | 
|---|
 | 86 |     }
 | 
|---|
 | 87 |     return (double)totalLen / (double)N;
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
| [01db301] | 90 | volatile int checkthis = 0;
 | 
|---|
 | 91 | #define MAYBE( op ) if (checkthis) { op; }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | int main( int argc, char ** argv ) {
 | 
|---|
 | 94 | 
 | 
|---|
| [4d0eb1c] | 95 |     STRING_SHARING_CONTROL
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 |     const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus...";
 | 
|---|
 | 99 |     const int static_arg_posns = 3;
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 |     int concatsPerReset = -1, execTimeSecs = -1;
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 |     switch (min(argc, static_arg_posns)) {
 | 
|---|
 | 104 |       case 3: execTimeSecs = atoi(argv[2]);
 | 
|---|
 | 105 |       case 2: concatsPerReset = atoi(argv[1]);
 | 
|---|
 | 106 |     }
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |     int corpuslen = argc - static_arg_posns;
 | 
|---|
 | 109 |     char ** corpus = argv + static_arg_posns;
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 |     if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) {
 | 
|---|
 | 112 |       printf("usage: %s %s\n", argv[0], usage_args);
 | 
|---|
 | 113 |       printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n");
 | 
|---|
 | 114 |       exit(1);
 | 
|---|
 | 115 |     }
 | 
|---|
| [01db301] | 116 | 
 | 
|---|
| [4d0eb1c] | 117 |     double meanCorpusLen = meanLen(corpuslen, corpus);
 | 
|---|
| [01db301] | 118 | 
 | 
|---|
| [4d0eb1c] | 119 |     clock_t start, end_target, end_actual;
 | 
|---|
| [01db301] | 120 | 
 | 
|---|
| [fefd77a] | 121 |     #if defined IMPL_CFA_LL && defined OP_PTA
 | 
|---|
 | 122 |         string_res pta_ll_temp;
 | 
|---|
 | 123 |     #endif
 | 
|---|
 | 124 | 
 | 
|---|
| [01db301] | 125 |     #if defined IMPL_CFA_LL
 | 
|---|
| [fefd77a] | 126 |       #define DECLS \
 | 
|---|
| [08ed947] | 127 |         const char* initval = "starter"; \
 | 
|---|
 | 128 |         string_res accum = initval;
 | 
|---|
| [fefd77a] | 129 |     #else
 | 
|---|
 | 130 |       #define DECLS \
 | 
|---|
| [08ed947] | 131 |         const char* initval = "starter"; \
 | 
|---|
| [fefd77a] | 132 |         string accum = initval;
 | 
|---|
 | 133 |     #endif
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |     #if defined ALLOC_REUSE
 | 
|---|
 | 136 |       DECLS
 | 
|---|
 | 137 |       #define RESET \
 | 
|---|
 | 138 |         accum = initval;
 | 
|---|
 | 139 |     #elif defined ALLOC_FRESH
 | 
|---|
 | 140 |       #define RESET \
 | 
|---|
 | 141 |         DECLS
 | 
|---|
| [01db301] | 142 |     #else
 | 
|---|
| [fefd77a] | 143 |       #error bad alloc
 | 
|---|
| [01db301] | 144 |     #endif
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 |     start = clock();
 | 
|---|
| [4d0eb1c] | 147 |     end_target = start + CLOCKS_PER_SEC * execTimeSecs;
 | 
|---|
 | 148 |     volatile unsigned int t = 0;
 | 
|---|
 | 149 |     for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
 | 
|---|
| [01db301] | 150 |             RESET
 | 
|---|
| [4d0eb1c] | 151 |             for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
 | 
|---|
| [fefd77a] | 152 |               MAYBE( PRINT(accum) )
 | 
|---|
| [4d0eb1c] | 153 |               char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
 | 
|---|
| [97d58dc] | 154 |               #if defined OP_PTA && defined IMPL_CFA_LL
 | 
|---|
| [fefd77a] | 155 |                  pta_ll_temp = accum;
 | 
|---|
 | 156 |                  pta_ll_temp += toAppend;
 | 
|---|
 | 157 |                  accum = pta_ll_temp;
 | 
|---|
| [97d58dc] | 158 |               #elif defined OP_PTA
 | 
|---|
| [fefd77a] | 159 |                  accum = accum + toAppend;
 | 
|---|
| [97d58dc] | 160 |               #elif defined OP_PEQ
 | 
|---|
| [fefd77a] | 161 |                  accum += toAppend;
 | 
|---|
| [08ed947] | 162 |               #else
 | 
|---|
 | 163 |                  #error Bad OP_
 | 
|---|
| [01db301] | 164 |               #endif
 | 
|---|
 | 165 |             }
 | 
|---|
 | 166 |     }
 | 
|---|
| [4d0eb1c] | 167 |     end_actual = clock();
 | 
|---|
 | 168 |     unsigned int concatsDone = t * concatsPerReset;
 | 
|---|
 | 169 |     double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
 | 
|---|
 | 170 |     printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
 | 
|---|
| [01db301] | 171 | 
 | 
|---|
| [08ed947] | 172 |     // malloc_stats();
 | 
|---|
 | 173 | 
 | 
|---|
| [01db301] | 174 |     return 0;
 | 
|---|
| [4d0eb1c] | 175 | }
 | 
|---|