#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; } 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 ) { #if defined OP_PFI size_t foundAt = #if defined IMPL_CFA find( corpus_imported[t % corpuslen], ' ') #elif defined IMPL_STL corpus_imported[t % corpuslen].find(' ') #else #error Bad IMPL #endif ; #else #error Bad OP_ #endif MAYBE( PRINT( foundAt ) ); } 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; }