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

Last change on this file since f858ca5 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
RevLine 
[08ed947]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
[01db301]8
9#if defined IMPL_STL
10 #include <string>
11 #include <iostream>
12 #include <cstdio>
13 using namespace std;
[4d0eb1c]14 #define IMPL_CXX
[01db301]15
16#elif defined IMPL_CFA_HL_SHARE
17 #define IMPL_CFA_HL
[4d0eb1c]18 #define IMPL_CFA
[01db301]19
20#elif defined IMPL_CFA_LL_SHARE
21 #define IMPL_CFA_LL
[4d0eb1c]22 #define IMPL_CFA
[01db301]23
24#elif defined IMPL_CFA_HL_NOSHARE
25 #define IMPL_CFA_HL
26 #define CFA_NOSHARE
[4d0eb1c]27 #define IMPL_CFA
[01db301]28
29#elif defined IMPL_CFA_LL_NOSHARE
30 #define IMPL_CFA_LL
31 #define CFA_NOSHARE
[4d0eb1c]32 #define IMPL_CFA
[01db301]33
34#elif defined IMPL_BUHR94
35 #include <iostream>
36 #include <cstdio>
37 #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
[4d0eb1c]38 #define IMPL_CXX
[01db301]39
40#else
41 #error Bad IMPL_
42#endif
43
44
45#if defined IMPL_CFA_HL
46 #include <string.hfa>
[7d02d35]47 #include <fstream.hfa>
[01db301]48#elif defined IMPL_CFA_LL
49 #include <string_res.hfa>
[7d02d35]50 #include <fstream.hfa>
[01db301]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
[4d0eb1c]61#if defined IMPL_CFA
62 #include <math.hfa>
[08ed947]63 extern "C" {
64 void malloc_stats( void );
65 }
[4d0eb1c]66#elif defined IMPL_CXX
67 #include <algorithm>
68 using std::min;
[08ed947]69 #include <malloc.h>
[4d0eb1c]70#endif
[01db301]71
72#include <time.h>
[4d0eb1c]73#include <stdlib.h> // atoi
74#include <string.h> // strlen, only during setup
[01db301]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
[4d0eb1c]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
[01db301]92volatile int checkthis = 0;
93#define MAYBE( op ) if (checkthis) { op; }
94
95int main( int argc, char ** argv ) {
96
[4d0eb1c]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 }
[01db301]118
[4d0eb1c]119 double meanCorpusLen = meanLen(corpuslen, corpus);
[01db301]120
[4d0eb1c]121 clock_t start, end_target, end_actual;
[01db301]122
[fefd77a]123 #if defined IMPL_CFA_LL && defined OP_PTA
124 string_res pta_ll_temp;
125 #endif
126
[01db301]127 #if defined IMPL_CFA_LL
[fefd77a]128 #define DECLS \
[08ed947]129 const char* initval = "starter"; \
130 string_res accum = initval;
[fefd77a]131 #else
132 #define DECLS \
[08ed947]133 const char* initval = "starter"; \
[fefd77a]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
[01db301]144 #else
[fefd77a]145 #error bad alloc
[01db301]146 #endif
147
148 start = clock();
[4d0eb1c]149 end_target = start + CLOCKS_PER_SEC * execTimeSecs;
150 volatile unsigned int t = 0;
151 for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
[01db301]152 RESET
[4d0eb1c]153 for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
[fefd77a]154 MAYBE( PRINT(accum) )
[4d0eb1c]155 char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
[97d58dc]156 #if defined OP_PTA && defined IMPL_CFA_LL
[fefd77a]157 pta_ll_temp = accum;
158 pta_ll_temp += toAppend;
159 accum = pta_ll_temp;
[97d58dc]160 #elif defined OP_PTA
[fefd77a]161 accum = accum + toAppend;
[97d58dc]162 #elif defined OP_PEQ
[fefd77a]163 accum += toAppend;
[08ed947]164 #else
165 #error Bad OP_
[01db301]166 #endif
167 }
168 }
[4d0eb1c]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);
[01db301]173
[08ed947]174 // malloc_stats();
175
[01db301]176 return 0;
[4d0eb1c]177}
Note: See TracBrowser for help on using the repository browser.