#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 #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 #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 && defined OP_PTA string_res pta_ll_temp; #endif #if defined IMPL_CFA_LL #define DECLS \ const char* initval = "starter"; \ string_res accum = initval; #else #define DECLS \ const char* initval = "starter"; \ string accum = initval; #endif #if defined ALLOC_REUSE DECLS #define RESET \ accum = initval; #elif defined ALLOC_FRESH #define RESET \ DECLS #else #error bad alloc #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(accum) ) char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen] #if defined OP_PTA && defined IMPL_CFA_LL pta_ll_temp = accum; pta_ll_temp += toAppend; accum = pta_ll_temp; #elif defined OP_PTA accum = accum + toAppend; #elif defined OP_PEQ accum += toAppend; #else #error Bad OP_ #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); // malloc_stats(); return 0; }