source: doc/theses/mike_brooks_MMath/benchmarks/string/prog-allocn.cfa

Last change on this file was e0350e0, checked in by Michael Brooks <mlbrooks@…>, 4 months ago

Recent rework of string benchmarks

  • Property mode set to 100644
File size: 5.9 KB
Line 
1#if defined IMPL_STL_NA_NA
2 #define IMPL_STL
3#endif
4
5#if defined IMPL_BUHR94_NA_NA
6 #define IMPL_BUHR94
7#endif
8
9#if defined IMPL_STL
10 #include <string>
11 #include <iostream>
12 #include <cstdio>
13 using namespace std;
14 #define IMPL_CXX
15
16#elif defined IMPL_CFA_HL_SHARE
17 #define IMPL_CFA_HL
18 #define IMPL_CFA
19
20#elif defined IMPL_CFA_LL_SHARE
21 #define IMPL_CFA_LL
22 #define IMPL_CFA
23
24#elif defined IMPL_CFA_HL_NOSHARE
25 #define IMPL_CFA_HL
26 #define CFA_NOSHARE
27 #define IMPL_CFA
28
29#elif defined IMPL_CFA_LL_NOSHARE
30 #define IMPL_CFA_LL
31 #define CFA_NOSHARE
32 #define IMPL_CFA
33
34#elif defined IMPL_BUHR94
35 #include <iostream>
36 #include <cstdio>
37 #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
38 #define IMPL_CXX
39
40#else
41 #error Bad IMPL_
42#endif
43
44#if defined IMPL_CFA_HL
45 #include <string.hfa>
46 #include <fstream.hfa>
47 extern void TUNING_set_string_heap_liveness_threshold(double); // in string_res.hfa
48#elif defined IMPL_CFA_LL
49
50// fichmich
51
52 #define EXPERIMENT_SEP_COMP_DISABLED
53 #include <string_res.cfa>
54 #include <fstream.hfa>
55#endif
56
57#if defined CFA_NOSHARE
58 #include <string_sharectx.hfa>
59 #define STRING_SHARING_CONTROL \
60 string_sharectx c = { NO_SHARING };
61#else
62 #define STRING_SHARING_CONTROL
63#endif
64
65#if defined IMPL_CFA
66 #include <math.hfa>
67 extern "C" {
68 void malloc_stats( void );
69 }
70#elif defined IMPL_CXX
71 #include <algorithm>
72 using std::min;
73 #include <malloc.h>
74#endif
75
76#include <time.h>
77#include <stdlib.h> // atoi
78#include <string.h> // strlen, only during setup
79
80#if defined IMPL_STL || defined IMPL_BUHR94
81 #define PRINT(s) std::cout << s << std::endl
82#elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
83 #define PRINT(s) sout | s;
84#else
85 #error Unhandled print case
86#endif
87
88#if defined IMPL_CFA_LL
89 #define STRING_T string_res
90 #define ASSIGN_CHAR(str, idx, val) assignAt(str, idx, val)
91#else
92 #define STRING_T string
93 #define ASSIGN_CHAR(str, idx, val) str[idx] = val
94#endif
95
96double meanLen(int N, char ** strings) {
97 int totalLen = 0;
98 for (int i = 0 ; i < N; i ++) {
99 totalLen += strlen(strings[i]);
100 }
101 return (double)totalLen / (double)N;
102}
103
104volatile int checkthis = 0;
105#define MAYBE( op ) if (checkthis) { op; }
106
107int corpuslen = 0;
108char ** corpus = (char**) 0;
109size_t corpus_next_pos = 0;
110
111double repsPerLevel;
112double repBalance = 0.0000001;
113
114clock_t start, endTarget, end_actual;
115size_t allocationCountTarget = 0;
116
117size_t allocationCountActual = 0;
118//size_t allocationBytesActual = 0;
119
120void helper( int depth ) {
121
122 if (depth == 0) return;
123
124 corpus_next_pos += 1;
125 corpus_next_pos %= corpuslen;
126
127 STRING_T q = corpus[corpus_next_pos];
128// ASSIGN_CHAR(q, 0, '@'); // Turns out my implementation is slow at this step. A separate test could work it. It's inessential to the allocation test, given the assumption that both string reps allocate eagerly in their heaps from a constant. In the STL, that assumption is upheld by my observation that commenting out this line didn't speed it up. In CFA-share, I know it to be true of the implementation.
129
130 allocationCountActual += 1;
131// allocationBytesActual += q`len;
132
133// if (depth > 0) {
134
135 repBalance += repsPerLevel;
136 int curRepLimit = repBalance;
137 repBalance -= curRepLimit;
138
139 for ( int i = 0 ; i < curRepLimit; i++ ) {
140 if ((allocationCountActual+1) % allocationCountTarget == 0 && clock() > endTarget) return;
141 helper(depth-1);
142 }
143// }
144
145 MAYBE(PRINT(q));
146}
147
148int main( int argc, char ** argv ) {
149
150 STRING_SHARING_CONTROL
151
152
153 const char * usage_args[] = {"Depth RepsPerLevel ExpansionThreshold ExecTimeSecs Corpus...",
154 "Depth RepsPerLevel ExpansionThreshold -w WorkAllocCount Corpus..."};
155 const int static_arg_posns = 5;
156 int used_arg_posns = static_arg_posns;
157
158 int launchDepth = -1;
159 double expansionThreshold = -1.0;
160 int execTimeSecs = -1;
161
162 switch (min(argc, static_arg_posns)) {
163 case 5: if ( strcmp(argv[4], "-w") == 0 ) {
164 used_arg_posns ++;
165 allocationCountTarget = atoi(argv[5]);
166 } else {
167 execTimeSecs = atoi(argv[4]);
168 }
169 case 4: expansionThreshold = atof(argv[3]);
170 case 3: repsPerLevel = atof(argv[2]);
171 case 2: launchDepth = atoi(argv[1]);
172 }
173
174 corpuslen = argc - used_arg_posns;
175 corpus = argv + used_arg_posns;
176
177 if (launchDepth < 1 || repsPerLevel < 1.0 || (execTimeSecs < 1 && allocationCountTarget < 1) || corpuslen < 1 ||
178 (expansionThreshold != -1.0 && (expansionThreshold <= 0.0 || expansionThreshold >= 1.0))) {
179 for (int u = 0; u < sizeof(usage_args) / sizeof(*usage_args); u++) {
180 printf("usage: %s %s\n", argv[0], usage_args[u]);
181 }
182 printf("output:\nxxx,corpusItemCount,corpusMeanLenChars,allocationCountActual,execTimeActualSec,topIters\n");
183 exit(1);
184 }
185
186 if (expansionThreshold != -1.0 ) {
187 #if defined IMPL_CFA
188 TUNING_set_string_heap_liveness_threshold(expansionThreshold);
189 #else
190 printf("cannot set expansion threshold on non-CFA implementation");
191 exit(1);
192 #endif
193 }
194
195 double meanCorpusLen = meanLen(corpuslen, corpus);
196
197 // time driven experiment: re-check time every 10000 allocations
198 if (execTimeSecs > 0) allocationCountTarget = 10000;
199
200 start = clock();
201 endTarget = start + CLOCKS_PER_SEC * max(0, execTimeSecs);
202
203 size_t top_iters = 0;
204
205 for(;;) {
206 #if defined OP_PALL
207 helper( launchDepth );
208 #else
209 #error Bad OP_
210 #endif
211
212 top_iters++;
213
214 if ((allocationCountActual+1) % allocationCountTarget == 0 && clock() > endTarget) break;
215 }
216 end_actual = clock();
217 double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
218 printf("xxx,%d,%f,%ld,%f,%ld\n", corpuslen, meanCorpusLen, allocationCountActual, elapsed, top_iters);
219
220 // malloc_stats();
221
222 return 0;
223}
Note: See TracBrowser for help on using the repository browser.