#if defined IMPL_STL_NA_NA #define IMPL_STL #endif #if defined IMPL_BUHR94_NA_NA #define IMPL_BUHR94 #endif #if defined IMPL_STL #include #include #include using namespace std; #define IMPL_CXX #elif defined IMPL_CFA_HL_SHARE #define IMPL_CFA_HL #define IMPL_CFA #elif defined IMPL_CFA_LL_SHARE #define IMPL_CFA_LL #define IMPL_CFA #elif defined IMPL_CFA_HL_NOSHARE #define IMPL_CFA_HL #define CFA_NOSHARE #define IMPL_CFA #elif defined IMPL_CFA_LL_NOSHARE #define IMPL_CFA_LL #define CFA_NOSHARE #define IMPL_CFA #elif defined IMPL_BUHR94 #include #include #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h" #define IMPL_CXX #else #error Bad IMPL_ #endif #if defined IMPL_CFA_HL #include #elif defined IMPL_CFA_LL #include #include "not_string_res.hfa" #endif #if defined CFA_NOSHARE #include #define STRING_SHARING_CONTROL \ string_sharectx c = { NO_SHARING }; #else #define STRING_SHARING_CONTROL #endif #if defined IMPL_CFA #include extern "C" { void malloc_stats( void ); } #elif defined IMPL_CXX #include using std::min; #include #endif #include #include // atoi #include // strlen, only during setup #include // LONG_MAX #if defined IMPL_STL || defined IMPL_BUHR94 #define PRINT(s) std::cout << s << std::endl #elif defined IMPL_CFA_HL || defined IMPL_CFA_LL #define PRINT(s) sout | s; #else #error Unhandled print case #endif #if defined IMPL_CFA_LL #define STRING_T string_res #define ASSIGN_CHAR(str, idx, val) assignAt(str, idx, val) #else #define STRING_T string #define ASSIGN_CHAR(str, idx, val) str[idx] = val #endif double meanLen(int N, char ** strings) { int totalLen = 0; for (int i = 0 ; i < N; i ++) { totalLen += strlen(strings[i]); } return (double)totalLen / (double)N; } volatile int checkthis = 0; #define MAYBE( op ) if (checkthis) { op; } #if defined IMPL_CFA_LL void helper( string_res & q ) { #else #error bad IMPL_ #endif #if defined OP_PB1X || defined OP_PB2X || defined OP_PB3X || defined OP_PB4X || defined OP_PB5X || defined OP_PB6X ASSIGN_CHAR(q, 0, '@'); #else MAYBE(ASSIGN_CHAR(q, 0, '@')); #endif MAYBE(PRINT(q)); } void not_helper( not_string_res & q ) { MAYBE( printf("%ld", q.junk[3]) ); MAYBE( q.junk[3] = 17 ); } int main( int argc, char ** argv ) { STRING_SHARING_CONTROL const char * usage_args[] = {"(Ignored) ExecTimeSecs Corpus...", "(Ignored) -w WorkAllocCount Corpus..."}; const int static_arg_posns = 3; int used_arg_posns = static_arg_posns; int execTimeSecs = -1; long int iterationCountTarget = -1; switch (min(argc, static_arg_posns)) { case 3: if ( strcmp(argv[2], "-w") == 0 ) { used_arg_posns ++; execTimeSecs = 0; iterationCountTarget = atoi(argv[3]); } else { execTimeSecs = atoi(argv[2]); iterationCountTarget = LONG_MAX; } } int corpuslen = argc - used_arg_posns; char ** corpus = argv + used_arg_posns; if ((execTimeSecs < 1 && iterationCountTarget < 1) || corpuslen < 1) { for (int u = 0; u < sizeof(usage_args) / sizeof(*usage_args); u++) { printf("usage: %s %s\n", argv[0], usage_args[u]); } printf("output:\nxxx,corpusItemCount,corpusMeanLenChars,callDoneActualCount,execTimeActualSec\n"); exit(1); } double meanCorpusLen = meanLen(corpuslen, corpus); clock_t start, end_target, end_actual; STRING_T corpus_imported[corpuslen]; for (int i = 0; i < corpuslen; i++) { corpus_imported[i] = corpus[i]; // if the callee ever modifies, then we will drive GCs, which will visit the entire corpus } start = clock(); if (execTimeSecs != 0) { end_target = start + CLOCKS_PER_SEC * execTimeSecs; } else { end_target = start + CLOCKS_PER_SEC * 3600; } unsigned int t = 0; for ( ; t < iterationCountTarget && ((t+1) % 10000 != 0 || clock() < end_target) ; t += 1 ) { string_res & src = corpus_imported[t % corpuslen]; size_t srclen = size(src); if (srclen < 2) { printf("need string lengths >= 2"); } #if defined OP_PB1 || defined OP_PB1X helper( (string_res){ src, COPY_VALUE, 1, srclen-1 } ); #elif defined OP_PB2 || defined OP_PB2X helper( (string_res){ src, SHARE_EDITS, 1, srclen-1 } ); #elif defined OP_PB3 || defined OP_PB3X helper( (string_res){ src, COPY_VALUE, 0, srclen } ); #elif defined OP_PB4 || defined OP_PB4X helper( (string_res){ src, SHARE_EDITS, 0, srclen } ); #elif defined OP_PB5 || defined OP_PB5X helper( (string_res){ src, COPY_VALUE } ); #elif defined OP_PB6 || defined OP_PB6X helper( src ); #elif defined OP_PB9 not_helper( (not_string_res){ src, SHARE_EDITS, 0, srclen } ); #else #error Bad OP_ #endif } end_actual = clock(); unsigned int callsDone = t; double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC; printf("xxx,%d,%f,%d,%f\n", corpuslen, meanCorpusLen, t, elapsed); // malloc_stats(); return 0; }