source: doc/theses/mike_brooks_MMath/benchmarks/string/prog-passbyval.cfa@ e0350e0

Last change on this file since e0350e0 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: 3.7 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
84#if defined IMPL_CFA_LL
85 #define STRING_T string_res
86 #define ASSIGN_CHAR(str, idx, val) assignAt(str, idx, val)
87#else
88 #define STRING_T string
89 #define ASSIGN_CHAR(str, idx, val) str[idx] = val
90#endif
91
92double meanLen(int N, char ** strings) {
93 int totalLen = 0;
94 for (int i = 0 ; i < N; i ++) {
95 totalLen += strlen(strings[i]);
96 }
97 return (double)totalLen / (double)N;
98}
99
100volatile int checkthis = 0;
101#define MAYBE( op ) if (checkthis) { op; }
102
103
104#if defined IMPL_CFA_LL
105void helper( string_res & qref ) {
106 string_res q = { qref, COPY_VALUE };
107#else
108void helper( string q ) {
109#endif
110 MAYBE(ASSIGN_CHAR(q, 0, '@'));
111 MAYBE(PRINT(q));
112}
113
114int main( int argc, char ** argv ) {
115
116 STRING_SHARING_CONTROL
117
118
119 const char * usage_args = "(Ignored) ExecTimeSecs Corpus...";
120 const int static_arg_posns = 3;
121
122 int execTimeSecs = -1;
123
124 switch (min(argc, static_arg_posns)) {
125 case 3: execTimeSecs = atoi(argv[2]);
126 }
127
128 int corpuslen = argc - static_arg_posns;
129 char ** corpus = argv + static_arg_posns;
130
131 if (execTimeSecs < 1 || corpuslen < 1) {
132 printf("usage: %s %s\n", argv[0], usage_args);
133 printf("output:\nxxx,corpusItemCount,corpusMeanLenChars,callDoneActualCount,execTimeActualSec\n");
134 exit(1);
135 }
136
137 double meanCorpusLen = meanLen(corpuslen, corpus);
138
139 clock_t start, end_target, end_actual;
140
141 STRING_T corpus_imported[corpuslen];
142
143 for (int i = 0; i < corpuslen; i++) {
144 corpus_imported[i] = corpus[i];
145 // if the callee ever modifies, then we will drive GCs, which will visit the entire corpus
146 }
147
148 start = clock();
149 end_target = start + CLOCKS_PER_SEC * execTimeSecs;
150 unsigned int t = 0;
151 for ( ; t % 10000 != 0 || clock() < end_target ; t += 1 ) {
152 #if defined OP_PBV
153 helper( corpus_imported[t % corpuslen] );
154 #else
155 #error Bad OP_
156 #endif
157 }
158 end_actual = clock();
159 unsigned int callsDone = t;
160 double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
161 printf("xxx,%d,%f,%d,%f\n", corpuslen, meanCorpusLen, t, elapsed);
162
163 // malloc_stats();
164
165 return 0;
166}
Note: See TracBrowser for help on using the repository browser.