#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 #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 #elif defined IMPL_CXX #include using std::min; #endif #include #include // atoi #include // strlen, only during setup #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 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; } int main( int argc, char ** argv ) { STRING_SHARING_CONTROL const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus..."; const int static_arg_posns = 3; int concatsPerReset = -1, execTimeSecs = -1; switch (min(argc, static_arg_posns)) { case 3: execTimeSecs = atoi(argv[2]); case 2: concatsPerReset = atoi(argv[1]); } int corpuslen = argc - static_arg_posns; char ** corpus = argv + static_arg_posns; if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) { printf("usage: %s %s\n", argv[0], usage_args); printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n"); exit(1); } double meanCorpusLen = meanLen(corpuslen, corpus); clock_t start, end_target, end_actual; #if defined IMPL_CFA_LL string_res x = "starter"; string_res y; #if defined OP_PLUS_THEN_ASSIGN string_res z; #endif #define RESET y = x; #else string x = "starter"; string y; #define RESET y = x; #endif start = clock(); end_target = start + CLOCKS_PER_SEC * execTimeSecs; volatile unsigned int t = 0; for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) { RESET for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) { MAYBE( PRINT(y) ) char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen] #if defined OP_PLUS_THEN_ASSIGN && defined IMPL_CFA_LL z = y; z += toAppend; y = z; #elif defined OP_PLUS_THEN_ASSIGN y = y + toAppend; #elif defined OP_PLUSEQ y += toAppend; #endif } } end_actual = clock(); unsigned int concatsDone = t * concatsPerReset; double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC; printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed); return 0; }