source: tests/zombies/string-perf/prog-passbyval.cfa@ 67408114

ADT ast-experimental
Last change on this file since 67408114 was 08ed947, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Roll up of string changes for performance testing/improvement, and a couple API features supporting them.

String API changes:
Defining a tuning knob to control the heap growth policy (relapaces former 10% hardcode, downgraded to a default)
Implementing findFrom (allowing find-non-first); leaving find as find-first.

String implementation perf improvements:
Calling C-malloc directly instead of via CFA-alloc.
Replacings loops that copy with memmove calls.
Replacings loops that search for a value with memchr calls.

String perf testing realized:
Makefile supporting several prog-*.cfa, chosen by OPERATION value (implies prog.cfa changes to support the adjusted protocol)
Adjusting the starter/accumulater declarations in PEQ and PTA to behave consistently in cfa v cpp.
Adding tests: allocation, find, normalize, pass-by-val, pass-by-x.
Adding helper shell scripts for: generating flame graphs, collecting/crunching allocation stats using Mubeen's malloc wrappers

  • 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#elif defined IMPL_CFA_LL
48 #include <string_res.hfa>
49#endif
50
51#if defined CFA_NOSHARE
52 #include <string_sharectx.hfa>
53 #define STRING_SHARING_CONTROL \
54 string_sharectx c = { NO_SHARING };
55#else
56 #define STRING_SHARING_CONTROL
57#endif
58
59#if defined IMPL_CFA
60 #include <math.hfa>
61 extern "C" {
62 void malloc_stats( void );
63 }
64#elif defined IMPL_CXX
65 #include <algorithm>
66 using std::min;
67 #include <malloc.h>
68#endif
69
70#include <time.h>
71#include <stdlib.h> // atoi
72#include <string.h> // strlen, only during setup
73
74#if defined IMPL_STL || defined IMPL_BUHR94
75 #define PRINT(s) std::cout << s << std::endl
76#elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
77 #define PRINT(s) sout | s;
78#else
79 #error Unhandled print case
80#endif
81
82#if defined IMPL_CFA_LL
83 #define STRING_T string_res
84 #define ASSIGN_CHAR(str, idx, val) assignAt(str, idx, val)
85#else
86 #define STRING_T string
87 #define ASSIGN_CHAR(str, idx, val) str[idx] = val
88#endif
89
90double meanLen(int N, char ** strings) {
91 int totalLen = 0;
92 for (int i = 0 ; i < N; i ++) {
93 totalLen += strlen(strings[i]);
94 }
95 return (double)totalLen / (double)N;
96}
97
98volatile int checkthis = 0;
99#define MAYBE( op ) if (checkthis) { op; }
100
101
102#if defined IMPL_CFA_LL
103void helper( string_res & qref ) {
104 string_res q = { qref, COPY_VALUE };
105#else
106void helper( string q ) {
107#endif
108 MAYBE(ASSIGN_CHAR(q, 0, '@'));
109 MAYBE(PRINT(q));
110}
111
112int main( int argc, char ** argv ) {
113
114 STRING_SHARING_CONTROL
115
116
117 const char * usage_args = "(Ignored) ExecTimeSecs Corpus...";
118 const int static_arg_posns = 3;
119
120 int execTimeSecs = -1;
121
122 switch (min(argc, static_arg_posns)) {
123 case 3: execTimeSecs = atoi(argv[2]);
124 }
125
126 int corpuslen = argc - static_arg_posns;
127 char ** corpus = argv + static_arg_posns;
128
129 if (execTimeSecs < 1 || corpuslen < 1) {
130 printf("usage: %s %s\n", argv[0], usage_args);
131 printf("output:\nxxx,corpusItemCount,corpusMeanLenChars,callDoneActualCount,execTimeActualSec\n");
132 exit(1);
133 }
134
135 double meanCorpusLen = meanLen(corpuslen, corpus);
136
137 clock_t start, end_target, end_actual;
138
139 STRING_T corpus_imported[corpuslen];
140
141 for (int i = 0; i < corpuslen; i++) {
142 corpus_imported[i] = corpus[i];
143 // if the callee ever modifies, then we will drive GCs, which will visit the entire corpus
144 }
145
146 start = clock();
147 end_target = start + CLOCKS_PER_SEC * execTimeSecs;
148 unsigned int t = 0;
149 for ( ; t % 10000 != 0 || clock() < end_target ; t += 1 ) {
150 #if defined OP_PBV
151 helper( corpus_imported[t % corpuslen] );
152 #else
153 #error Bad OP_
154 #endif
155 }
156 end_actual = clock();
157 unsigned int callsDone = t;
158 double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
159 printf("xxx,%d,%f,%d,%f\n", corpuslen, meanCorpusLen, t, elapsed);
160
161 // malloc_stats();
162
163 return 0;
164}
Note: See TracBrowser for help on using the repository browser.