| 1 |
|
|---|
| 2 | #if defined IMPL_STL
|
|---|
| 3 | #include <string>
|
|---|
| 4 | #include <iostream>
|
|---|
| 5 | #include <cstdio>
|
|---|
| 6 | using namespace std;
|
|---|
| 7 | #define IMPL_CXX
|
|---|
| 8 |
|
|---|
| 9 | #elif defined IMPL_CFA_HL_SHARE
|
|---|
| 10 | #define IMPL_CFA_HL
|
|---|
| 11 | #define IMPL_CFA
|
|---|
| 12 |
|
|---|
| 13 | #elif defined IMPL_CFA_LL_SHARE
|
|---|
| 14 | #define IMPL_CFA_LL
|
|---|
| 15 | #define IMPL_CFA
|
|---|
| 16 |
|
|---|
| 17 | #elif defined IMPL_CFA_HL_NOSHARE
|
|---|
| 18 | #define IMPL_CFA_HL
|
|---|
| 19 | #define CFA_NOSHARE
|
|---|
| 20 | #define IMPL_CFA
|
|---|
| 21 |
|
|---|
| 22 | #elif defined IMPL_CFA_LL_NOSHARE
|
|---|
| 23 | #define IMPL_CFA_LL
|
|---|
| 24 | #define CFA_NOSHARE
|
|---|
| 25 | #define IMPL_CFA
|
|---|
| 26 |
|
|---|
| 27 | #elif defined IMPL_BUHR94
|
|---|
| 28 | #include <iostream>
|
|---|
| 29 | #include <cstdio>
|
|---|
| 30 | #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
|
|---|
| 31 | #define IMPL_CXX
|
|---|
| 32 |
|
|---|
| 33 | #else
|
|---|
| 34 | #error Bad IMPL_
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | #if defined IMPL_CFA_HL
|
|---|
| 39 | #include <string.hfa>
|
|---|
| 40 | #elif defined IMPL_CFA_LL
|
|---|
| 41 | #include <string_res.hfa>
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | #if defined CFA_NOSHARE
|
|---|
| 45 | #include <string_sharectx.hfa>
|
|---|
| 46 | #define STRING_SHARING_CONTROL \
|
|---|
| 47 | string_sharectx c = { NO_SHARING };
|
|---|
| 48 | #else
|
|---|
| 49 | #define STRING_SHARING_CONTROL
|
|---|
| 50 | #endif
|
|---|
| 51 |
|
|---|
| 52 | #if defined IMPL_CFA
|
|---|
| 53 | #include <math.hfa>
|
|---|
| 54 | #elif defined IMPL_CXX
|
|---|
| 55 | #include <algorithm>
|
|---|
| 56 | using std::min;
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #include <time.h>
|
|---|
| 60 | #include <stdlib.h> // atoi
|
|---|
| 61 | #include <string.h> // strlen, only during setup
|
|---|
| 62 |
|
|---|
| 63 | #if defined IMPL_STL || defined IMPL_BUHR94
|
|---|
| 64 | #define PRINT(s) std::cout << s << std::endl
|
|---|
| 65 | #elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
|
|---|
| 66 | #define PRINT(s) sout | s;
|
|---|
| 67 | #else
|
|---|
| 68 | #error Unhandled print case
|
|---|
| 69 | #endif
|
|---|
| 70 |
|
|---|
| 71 | double meanLen(int N, char ** strings) {
|
|---|
| 72 | int totalLen = 0;
|
|---|
| 73 | for (int i = 0 ; i < N; i ++) {
|
|---|
| 74 | totalLen += strlen(strings[i]);
|
|---|
| 75 | }
|
|---|
| 76 | return (double)totalLen / (double)N;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | volatile int checkthis = 0;
|
|---|
| 80 | #define MAYBE( op ) if (checkthis) { op; }
|
|---|
| 81 |
|
|---|
| 82 | int main( int argc, char ** argv ) {
|
|---|
| 83 |
|
|---|
| 84 | STRING_SHARING_CONTROL
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus...";
|
|---|
| 88 | const int static_arg_posns = 3;
|
|---|
| 89 |
|
|---|
| 90 | int concatsPerReset = -1, execTimeSecs = -1;
|
|---|
| 91 |
|
|---|
| 92 | switch (min(argc, static_arg_posns)) {
|
|---|
| 93 | case 3: execTimeSecs = atoi(argv[2]);
|
|---|
| 94 | case 2: concatsPerReset = atoi(argv[1]);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | int corpuslen = argc - static_arg_posns;
|
|---|
| 98 | char ** corpus = argv + static_arg_posns;
|
|---|
| 99 |
|
|---|
| 100 | if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) {
|
|---|
| 101 | printf("usage: %s %s\n", argv[0], usage_args);
|
|---|
| 102 | printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n");
|
|---|
| 103 | exit(1);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | double meanCorpusLen = meanLen(corpuslen, corpus);
|
|---|
| 107 |
|
|---|
| 108 | clock_t start, end_target, end_actual;
|
|---|
| 109 |
|
|---|
| 110 | #if defined IMPL_CFA_LL
|
|---|
| 111 | string_res x = "starter";
|
|---|
| 112 | string_res y;
|
|---|
| 113 | #if defined OP_PTA
|
|---|
| 114 | string_res z;
|
|---|
| 115 | #endif
|
|---|
| 116 | #define RESET y = x;
|
|---|
| 117 | #else
|
|---|
| 118 | string x = "starter";
|
|---|
| 119 | string y;
|
|---|
| 120 | #define RESET y = x;
|
|---|
| 121 | #endif
|
|---|
| 122 |
|
|---|
| 123 | start = clock();
|
|---|
| 124 | end_target = start + CLOCKS_PER_SEC * execTimeSecs;
|
|---|
| 125 | volatile unsigned int t = 0;
|
|---|
| 126 | for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
|
|---|
| 127 | RESET
|
|---|
| 128 | for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
|
|---|
| 129 | MAYBE( PRINT(y) )
|
|---|
| 130 | char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
|
|---|
| 131 | #if defined OP_PTA && defined IMPL_CFA_LL
|
|---|
| 132 | z = y;
|
|---|
| 133 | z += toAppend;
|
|---|
| 134 | y = z;
|
|---|
| 135 | #elif defined OP_PTA
|
|---|
| 136 | y = y + toAppend;
|
|---|
| 137 | #elif defined OP_PEQ
|
|---|
| 138 | y += toAppend;
|
|---|
| 139 | #endif
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | end_actual = clock();
|
|---|
| 143 | unsigned int concatsDone = t * concatsPerReset;
|
|---|
| 144 | double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
|
|---|
| 145 | printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
|
|---|
| 146 |
|
|---|
| 147 | return 0;
|
|---|
| 148 | }
|
|---|