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

Last change on this file was 7d02d35, checked in by Mike Brooks <mlbrooks@…>, 4 months ago

Include benchmark changes for data production in string-plot data WIP. Missing from 2410424.

  • Property mode set to 100644
File size: 4.2 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
45#if defined IMPL_CFA_HL
46 #include <string.hfa>
47 #include <fstream.hfa>
48#elif defined IMPL_CFA_LL
49 #include <string_res.hfa>
50 #include <fstream.hfa>
51#endif
52
53#if defined CFA_NOSHARE
54 #include <string_sharectx.hfa>
55 #define STRING_SHARING_CONTROL \
56 string_sharectx c = { NO_SHARING };
57#else
58 #define STRING_SHARING_CONTROL
59#endif
60
61#if defined IMPL_CFA
62 #include <math.hfa>
63 extern "C" {
64 void malloc_stats( void );
65 }
66#elif defined IMPL_CXX
67 #include <algorithm>
68 using std::min;
69 #include <malloc.h>
70#endif
71
72#include <time.h>
73#include <stdlib.h> // atoi
74#include <string.h> // strlen, only during setup
75
76#if defined IMPL_STL || defined IMPL_BUHR94
77 #define PRINT(s) std::cout << s << std::endl
78#elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
79 #define PRINT(s) sout | s;
80#else
81 #error Unhandled print case
82#endif
83
84double meanLen(int N, char ** strings) {
85 int totalLen = 0;
86 for (int i = 0 ; i < N; i ++) {
87 totalLen += strlen(strings[i]);
88 }
89 return (double)totalLen / (double)N;
90}
91
92volatile int checkthis = 0;
93#define MAYBE( op ) if (checkthis) { op; }
94
95int main( int argc, char ** argv ) {
96
97 STRING_SHARING_CONTROL
98
99
100 const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus...";
101 const int static_arg_posns = 3;
102
103 int concatsPerReset = -1, execTimeSecs = -1;
104
105 switch (min(argc, static_arg_posns)) {
106 case 3: execTimeSecs = atoi(argv[2]);
107 case 2: concatsPerReset = atoi(argv[1]);
108 }
109
110 int corpuslen = argc - static_arg_posns;
111 char ** corpus = argv + static_arg_posns;
112
113 if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) {
114 printf("usage: %s %s\n", argv[0], usage_args);
115 printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n");
116 exit(1);
117 }
118
119 double meanCorpusLen = meanLen(corpuslen, corpus);
120
121 clock_t start, end_target, end_actual;
122
123 #if defined IMPL_CFA_LL && defined OP_PTA
124 string_res pta_ll_temp;
125 #endif
126
127 #if defined IMPL_CFA_LL
128 #define DECLS \
129 const char* initval = "starter"; \
130 string_res accum = initval;
131 #else
132 #define DECLS \
133 const char* initval = "starter"; \
134 string accum = initval;
135 #endif
136
137 #if defined ALLOC_REUSE
138 DECLS
139 #define RESET \
140 accum = initval;
141 #elif defined ALLOC_FRESH
142 #define RESET \
143 DECLS
144 #else
145 #error bad alloc
146 #endif
147
148 start = clock();
149 end_target = start + CLOCKS_PER_SEC * execTimeSecs;
150 volatile unsigned int t = 0;
151 for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
152 RESET
153 for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
154 MAYBE( PRINT(accum) )
155 char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
156 #if defined OP_PTA && defined IMPL_CFA_LL
157 pta_ll_temp = accum;
158 pta_ll_temp += toAppend;
159 accum = pta_ll_temp;
160 #elif defined OP_PTA
161 accum = accum + toAppend;
162 #elif defined OP_PEQ
163 accum += toAppend;
164 #else
165 #error Bad OP_
166 #endif
167 }
168 }
169 end_actual = clock();
170 unsigned int concatsDone = t * concatsPerReset;
171 double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
172 printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
173
174 // malloc_stats();
175
176 return 0;
177}
Note: See TracBrowser for help on using the repository browser.