| [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 | 
|---|
|  | 8 |  | 
|---|
|  | 9 | #if defined IMPL_STL | 
|---|
|  | 10 | #include <string> | 
|---|
|  | 11 | #include <iostream> | 
|---|
|  | 12 | #include <cstdio> | 
|---|
|  | 13 | using namespace std; | 
|---|
|  | 14 | #define IMPL_CXX | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #elif defined IMPL_CFA_HL_SHARE | 
|---|
|  | 17 | #define IMPL_CFA_HL | 
|---|
|  | 18 | #define IMPL_CFA | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #elif defined IMPL_CFA_LL_SHARE | 
|---|
|  | 21 | #define IMPL_CFA_LL | 
|---|
|  | 22 | #define IMPL_CFA | 
|---|
|  | 23 |  | 
|---|
|  | 24 | #elif defined IMPL_CFA_HL_NOSHARE | 
|---|
|  | 25 | #define IMPL_CFA_HL | 
|---|
|  | 26 | #define CFA_NOSHARE | 
|---|
|  | 27 | #define IMPL_CFA | 
|---|
|  | 28 |  | 
|---|
|  | 29 | #elif defined IMPL_CFA_LL_NOSHARE | 
|---|
|  | 30 | #define IMPL_CFA_LL | 
|---|
|  | 31 | #define CFA_NOSHARE | 
|---|
|  | 32 | #define IMPL_CFA | 
|---|
|  | 33 |  | 
|---|
|  | 34 | #elif defined IMPL_BUHR94 | 
|---|
|  | 35 | #include <iostream> | 
|---|
|  | 36 | #include <cstdio> | 
|---|
|  | 37 | #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h" | 
|---|
|  | 38 | #define IMPL_CXX | 
|---|
|  | 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 | #include "not_string_res.hfa" | 
|---|
|  | 50 | #endif | 
|---|
|  | 51 |  | 
|---|
|  | 52 | #if defined CFA_NOSHARE | 
|---|
|  | 53 | #include <string_sharectx.hfa> | 
|---|
|  | 54 | #define STRING_SHARING_CONTROL \ | 
|---|
|  | 55 | string_sharectx c = { NO_SHARING }; | 
|---|
|  | 56 | #else | 
|---|
|  | 57 | #define STRING_SHARING_CONTROL | 
|---|
|  | 58 | #endif | 
|---|
|  | 59 |  | 
|---|
|  | 60 | #if defined IMPL_CFA | 
|---|
|  | 61 | #include <math.hfa> | 
|---|
|  | 62 | extern "C" { | 
|---|
|  | 63 | void malloc_stats( void ); | 
|---|
|  | 64 | } | 
|---|
|  | 65 | #elif defined IMPL_CXX | 
|---|
|  | 66 | #include <algorithm> | 
|---|
|  | 67 | using std::min; | 
|---|
|  | 68 | #include <malloc.h> | 
|---|
|  | 69 | #endif | 
|---|
|  | 70 |  | 
|---|
|  | 71 | #include <time.h> | 
|---|
|  | 72 | #include <stdlib.h> // atoi | 
|---|
|  | 73 | #include <string.h> // strlen, only during setup | 
|---|
|  | 74 | #include <limits.h> // LONG_MAX | 
|---|
|  | 75 |  | 
|---|
|  | 76 | #if defined IMPL_STL || defined IMPL_BUHR94 | 
|---|
|  | 77 | #define PRINT(s) std::cout << s << std::endl | 
|---|
|  | 78 | #elif defined IMPL_CFA_HL || defined IMPL_CFA_LL | 
|---|
|  | 79 | #define PRINT(s) sout | s; | 
|---|
|  | 80 | #else | 
|---|
|  | 81 | #error Unhandled print case | 
|---|
|  | 82 | #endif | 
|---|
|  | 83 |  | 
|---|
|  | 84 | #if defined IMPL_CFA_LL | 
|---|
|  | 85 | #define STRING_T string_res | 
|---|
|  | 86 | #define ASSIGN_CHAR(str, idx, val) assignAt(str, idx, val) | 
|---|
|  | 87 | #else | 
|---|
|  | 88 | #define STRING_T string | 
|---|
|  | 89 | #define ASSIGN_CHAR(str, idx, val) str[idx] = val | 
|---|
|  | 90 | #endif | 
|---|
|  | 91 |  | 
|---|
|  | 92 | double meanLen(int N, char ** strings) { | 
|---|
|  | 93 | int totalLen = 0; | 
|---|
|  | 94 | for (int i = 0 ; i < N; i ++) { | 
|---|
|  | 95 | totalLen += strlen(strings[i]); | 
|---|
|  | 96 | } | 
|---|
|  | 97 | return (double)totalLen / (double)N; | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | volatile int checkthis = 0; | 
|---|
|  | 101 | #define MAYBE( op ) if (checkthis) { op; } | 
|---|
|  | 102 |  | 
|---|
|  | 103 |  | 
|---|
|  | 104 | #if defined IMPL_CFA_LL | 
|---|
|  | 105 | void helper( string_res & q ) { | 
|---|
|  | 106 | #else | 
|---|
|  | 107 | #error bad IMPL_ | 
|---|
|  | 108 | #endif | 
|---|
|  | 109 | #if defined OP_PB1X || defined OP_PB2X || defined OP_PB3X || defined OP_PB4X || defined OP_PB5X || defined OP_PB6X | 
|---|
|  | 110 | ASSIGN_CHAR(q, 0, '@'); | 
|---|
|  | 111 | #else | 
|---|
|  | 112 | MAYBE(ASSIGN_CHAR(q, 0, '@')); | 
|---|
|  | 113 | #endif | 
|---|
|  | 114 | MAYBE(PRINT(q)); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | void not_helper( not_string_res & q ) { | 
|---|
|  | 118 | MAYBE( printf("%ld", q.junk[3]) ); | 
|---|
|  | 119 | MAYBE( q.junk[3] = 17 ); | 
|---|
|  | 120 | } | 
|---|
|  | 121 |  | 
|---|
|  | 122 | int main( int argc, char ** argv ) { | 
|---|
|  | 123 |  | 
|---|
|  | 124 | STRING_SHARING_CONTROL | 
|---|
|  | 125 |  | 
|---|
|  | 126 |  | 
|---|
|  | 127 | const char * usage_args[] = {"(Ignored)    ExecTimeSecs   Corpus...", | 
|---|
|  | 128 | "(Ignored) -w WorkAllocCount Corpus..."}; | 
|---|
|  | 129 |  | 
|---|
|  | 130 | const int static_arg_posns = 3; | 
|---|
|  | 131 | int used_arg_posns = static_arg_posns; | 
|---|
|  | 132 |  | 
|---|
|  | 133 | int execTimeSecs = -1; | 
|---|
|  | 134 |  | 
|---|
|  | 135 | long int iterationCountTarget = -1; | 
|---|
|  | 136 |  | 
|---|
|  | 137 | switch (min(argc, static_arg_posns)) { | 
|---|
|  | 138 | case 3: if ( strcmp(argv[2], "-w") == 0 ) { | 
|---|
|  | 139 | used_arg_posns ++; | 
|---|
|  | 140 | execTimeSecs = 0; | 
|---|
|  | 141 | iterationCountTarget = atoi(argv[3]); | 
|---|
|  | 142 | } else { | 
|---|
|  | 143 | execTimeSecs = atoi(argv[2]); | 
|---|
|  | 144 | iterationCountTarget = LONG_MAX; | 
|---|
|  | 145 | } | 
|---|
|  | 146 | } | 
|---|
|  | 147 |  | 
|---|
|  | 148 | int corpuslen = argc - used_arg_posns; | 
|---|
|  | 149 | char ** corpus = argv + used_arg_posns; | 
|---|
|  | 150 |  | 
|---|
|  | 151 | if ((execTimeSecs < 1 && iterationCountTarget < 1)  || corpuslen < 1) { | 
|---|
|  | 152 | for (int u = 0; u < sizeof(usage_args) / sizeof(*usage_args); u++) { | 
|---|
|  | 153 | printf("usage: %s %s\n", argv[0], usage_args[u]); | 
|---|
|  | 154 | } | 
|---|
|  | 155 | printf("output:\nxxx,corpusItemCount,corpusMeanLenChars,callDoneActualCount,execTimeActualSec\n"); | 
|---|
|  | 156 | exit(1); | 
|---|
|  | 157 | } | 
|---|
|  | 158 |  | 
|---|
|  | 159 | double meanCorpusLen = meanLen(corpuslen, corpus); | 
|---|
|  | 160 |  | 
|---|
|  | 161 | clock_t start, end_target, end_actual; | 
|---|
|  | 162 |  | 
|---|
|  | 163 | STRING_T corpus_imported[corpuslen]; | 
|---|
|  | 164 |  | 
|---|
|  | 165 | for (int i = 0; i < corpuslen; i++) { | 
|---|
|  | 166 | corpus_imported[i] = corpus[i]; | 
|---|
|  | 167 | // if the callee ever modifies, then we will drive GCs, which will visit the entire corpus | 
|---|
|  | 168 | } | 
|---|
|  | 169 |  | 
|---|
|  | 170 | start = clock(); | 
|---|
|  | 171 | if (execTimeSecs != 0) { | 
|---|
|  | 172 | end_target = start + CLOCKS_PER_SEC * execTimeSecs; | 
|---|
|  | 173 | } else { | 
|---|
|  | 174 | end_target = start + CLOCKS_PER_SEC * 3600; | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 | unsigned int t = 0; | 
|---|
|  | 178 | for ( ; t < iterationCountTarget && ((t+1) % 10000 != 0 || clock() < end_target) ; t += 1 ) { | 
|---|
|  | 179 | string_res & src = corpus_imported[t % corpuslen]; | 
|---|
|  | 180 | size_t srclen = size(src); | 
|---|
|  | 181 | if (srclen < 2) { | 
|---|
|  | 182 | printf("need string lengths >= 2"); | 
|---|
|  | 183 | } | 
|---|
|  | 184 | #if defined OP_PB1 || defined OP_PB1X | 
|---|
|  | 185 | helper( (string_res){ src, COPY_VALUE, 1, srclen-1 } ); | 
|---|
|  | 186 | #elif defined OP_PB2 || defined OP_PB2X | 
|---|
|  | 187 | helper( (string_res){ src, SHARE_EDITS, 1, srclen-1 } ); | 
|---|
|  | 188 | #elif defined OP_PB3 || defined OP_PB3X | 
|---|
|  | 189 | helper( (string_res){ src, COPY_VALUE, 0, srclen } ); | 
|---|
|  | 190 | #elif defined OP_PB4 || defined OP_PB4X | 
|---|
|  | 191 | helper( (string_res){ src, SHARE_EDITS, 0, srclen } ); | 
|---|
|  | 192 | #elif defined OP_PB5 || defined OP_PB5X | 
|---|
|  | 193 | helper( (string_res){ src, COPY_VALUE } ); | 
|---|
|  | 194 | #elif defined OP_PB6 || defined OP_PB6X | 
|---|
|  | 195 | helper( src ); | 
|---|
|  | 196 | #elif defined OP_PB9 | 
|---|
|  | 197 | not_helper( (not_string_res){ src, SHARE_EDITS, 0, srclen } ); | 
|---|
|  | 198 | #else | 
|---|
|  | 199 | #error Bad OP_ | 
|---|
|  | 200 | #endif | 
|---|
|  | 201 | } | 
|---|
|  | 202 | end_actual = clock(); | 
|---|
|  | 203 | unsigned int callsDone = t; | 
|---|
|  | 204 | double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC; | 
|---|
|  | 205 | printf("xxx,%d,%f,%d,%f\n", corpuslen, meanCorpusLen, t, elapsed); | 
|---|
|  | 206 |  | 
|---|
|  | 207 | // malloc_stats(); | 
|---|
|  | 208 |  | 
|---|
|  | 209 | return 0; | 
|---|
|  | 210 | } | 
|---|