[01db301] | 1 |
|
---|
| 2 | #if defined IMPL_STL
|
---|
| 3 | #include <string>
|
---|
| 4 | #include <iostream>
|
---|
| 5 | #include <cstdio>
|
---|
| 6 | using namespace std;
|
---|
[4d0eb1c] | 7 | #define IMPL_CXX
|
---|
[01db301] | 8 |
|
---|
| 9 | #elif defined IMPL_CFA_HL_SHARE
|
---|
| 10 | #define IMPL_CFA_HL
|
---|
[4d0eb1c] | 11 | #define IMPL_CFA
|
---|
[01db301] | 12 |
|
---|
| 13 | #elif defined IMPL_CFA_LL_SHARE
|
---|
| 14 | #define IMPL_CFA_LL
|
---|
[4d0eb1c] | 15 | #define IMPL_CFA
|
---|
[01db301] | 16 |
|
---|
| 17 | #elif defined IMPL_CFA_HL_NOSHARE
|
---|
| 18 | #define IMPL_CFA_HL
|
---|
| 19 | #define CFA_NOSHARE
|
---|
[4d0eb1c] | 20 | #define IMPL_CFA
|
---|
[01db301] | 21 |
|
---|
| 22 | #elif defined IMPL_CFA_LL_NOSHARE
|
---|
| 23 | #define IMPL_CFA_LL
|
---|
| 24 | #define CFA_NOSHARE
|
---|
[4d0eb1c] | 25 | #define IMPL_CFA
|
---|
[01db301] | 26 |
|
---|
| 27 | #elif defined IMPL_BUHR94
|
---|
| 28 | #include <iostream>
|
---|
| 29 | #include <cstdio>
|
---|
| 30 | #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
|
---|
[4d0eb1c] | 31 | #define IMPL_CXX
|
---|
[01db301] | 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 |
|
---|
[4d0eb1c] | 52 | #if defined IMPL_CFA
|
---|
| 53 | #include <math.hfa>
|
---|
| 54 | #elif defined IMPL_CXX
|
---|
| 55 | #include <algorithm>
|
---|
| 56 | using std::min;
|
---|
| 57 | #endif
|
---|
[01db301] | 58 |
|
---|
| 59 | #include <time.h>
|
---|
[4d0eb1c] | 60 | #include <stdlib.h> // atoi
|
---|
| 61 | #include <string.h> // strlen, only during setup
|
---|
[01db301] | 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 |
|
---|
[4d0eb1c] | 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 |
|
---|
[01db301] | 79 | volatile int checkthis = 0;
|
---|
| 80 | #define MAYBE( op ) if (checkthis) { op; }
|
---|
| 81 |
|
---|
| 82 | int main( int argc, char ** argv ) {
|
---|
| 83 |
|
---|
[4d0eb1c] | 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 | }
|
---|
[01db301] | 105 |
|
---|
[4d0eb1c] | 106 | double meanCorpusLen = meanLen(corpuslen, corpus);
|
---|
[01db301] | 107 |
|
---|
[4d0eb1c] | 108 | clock_t start, end_target, end_actual;
|
---|
[01db301] | 109 |
|
---|
[fefd77a] | 110 | #if defined IMPL_CFA_LL && defined OP_PTA
|
---|
| 111 | string_res pta_ll_temp;
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|
[01db301] | 114 | #if defined IMPL_CFA_LL
|
---|
[fefd77a] | 115 | #define DECLS \
|
---|
| 116 | string_res initval = "starter"; \
|
---|
| 117 | string_res accum = { initval, COPY_VALUE };
|
---|
| 118 | #else
|
---|
| 119 | #define DECLS \
|
---|
| 120 | string initval = "starter"; \
|
---|
| 121 | string accum = initval;
|
---|
| 122 | #endif
|
---|
| 123 |
|
---|
| 124 | #if defined ALLOC_REUSE
|
---|
| 125 | DECLS
|
---|
| 126 | #define RESET \
|
---|
| 127 | accum = initval;
|
---|
| 128 | #elif defined ALLOC_FRESH
|
---|
| 129 | #define RESET \
|
---|
| 130 | DECLS
|
---|
[01db301] | 131 | #else
|
---|
[fefd77a] | 132 | #error bad alloc
|
---|
[01db301] | 133 | #endif
|
---|
| 134 |
|
---|
| 135 | start = clock();
|
---|
[4d0eb1c] | 136 | end_target = start + CLOCKS_PER_SEC * execTimeSecs;
|
---|
| 137 | volatile unsigned int t = 0;
|
---|
| 138 | for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
|
---|
[01db301] | 139 | RESET
|
---|
[4d0eb1c] | 140 | for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
|
---|
[fefd77a] | 141 | MAYBE( PRINT(accum) )
|
---|
[4d0eb1c] | 142 | char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
|
---|
[97d58dc] | 143 | #if defined OP_PTA && defined IMPL_CFA_LL
|
---|
[fefd77a] | 144 | pta_ll_temp = accum;
|
---|
| 145 | pta_ll_temp += toAppend;
|
---|
| 146 | accum = pta_ll_temp;
|
---|
[97d58dc] | 147 | #elif defined OP_PTA
|
---|
[fefd77a] | 148 | accum = accum + toAppend;
|
---|
[97d58dc] | 149 | #elif defined OP_PEQ
|
---|
[fefd77a] | 150 | accum += toAppend;
|
---|
[01db301] | 151 | #endif
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
[4d0eb1c] | 154 | end_actual = clock();
|
---|
| 155 | unsigned int concatsDone = t * concatsPerReset;
|
---|
| 156 | double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
|
---|
| 157 | printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
|
---|
[01db301] | 158 |
|
---|
| 159 | return 0;
|
---|
[4d0eb1c] | 160 | }
|
---|