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

enumpthread-emulationqualifiedEnum
Last change on this file since fefd77a was fefd77a, checked in by Michael Brooks <mlbrooks@…>, 11 months ago

String perf append test now compares stretch phase (alloc=fresh) with steady-state (alloc=reuse). Make gets rid of explicit list of targets. Running these with copori up to mean-500 lenght.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1
2#if defined IMPL_STL
3  #include <string>
4  #include <iostream>
5  #include <cstdio>
6  using namespace std;
7  #define IMPL_CXX
8
9#elif defined IMPL_CFA_HL_SHARE
10  #define IMPL_CFA_HL
11  #define IMPL_CFA
12
13#elif defined IMPL_CFA_LL_SHARE
14  #define IMPL_CFA_LL
15  #define IMPL_CFA
16
17#elif defined IMPL_CFA_HL_NOSHARE
18  #define IMPL_CFA_HL
19  #define CFA_NOSHARE
20  #define IMPL_CFA
21
22#elif defined IMPL_CFA_LL_NOSHARE
23  #define IMPL_CFA_LL
24  #define CFA_NOSHARE
25  #define IMPL_CFA
26
27#elif defined IMPL_BUHR94
28  #include <iostream>
29  #include <cstdio>
30  #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
31  #define IMPL_CXX
32
33#else
34  #error Bad IMPL_
35#endif
36
37
38#if defined IMPL_CFA_HL
39  #include <string.hfa>
40#elif defined IMPL_CFA_LL
41  #include <string_res.hfa>
42#endif
43
44#if defined CFA_NOSHARE
45  #include <string_sharectx.hfa>
46  #define STRING_SHARING_CONTROL \
47    string_sharectx c = { NO_SHARING };
48#else
49  #define STRING_SHARING_CONTROL
50#endif
51
52#if defined IMPL_CFA
53  #include <math.hfa>
54#elif defined IMPL_CXX
55  #include <algorithm>
56  using std::min;
57#endif
58
59#include <time.h>
60#include <stdlib.h> // atoi
61#include <string.h> // strlen, only during setup
62
63#if defined IMPL_STL || defined IMPL_BUHR94
64    #define PRINT(s) std::cout << s << std::endl
65#elif defined IMPL_CFA_HL || defined IMPL_CFA_LL
66    #define PRINT(s) sout | s;
67#else
68    #error Unhandled print case
69#endif
70
71double meanLen(int N, char ** strings) {
72    int totalLen = 0;
73    for (int i = 0 ; i < N; i ++) {
74        totalLen += strlen(strings[i]);
75    }
76    return (double)totalLen / (double)N;
77}
78
79volatile int checkthis = 0;
80#define MAYBE( op ) if (checkthis) { op; }
81
82int main( int argc, char ** argv ) {
83
84    STRING_SHARING_CONTROL
85
86
87    const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus...";
88    const int static_arg_posns = 3;
89
90    int concatsPerReset = -1, execTimeSecs = -1;
91
92    switch (min(argc, static_arg_posns)) {
93      case 3: execTimeSecs = atoi(argv[2]);
94      case 2: concatsPerReset = atoi(argv[1]);
95    }
96
97    int corpuslen = argc - static_arg_posns;
98    char ** corpus = argv + static_arg_posns;
99
100    if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) {
101      printf("usage: %s %s\n", argv[0], usage_args);
102      printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n");
103      exit(1);
104    }
105
106    double meanCorpusLen = meanLen(corpuslen, corpus);
107
108    clock_t start, end_target, end_actual;
109
110    #if defined IMPL_CFA_LL && defined OP_PTA
111        string_res pta_ll_temp;
112    #endif
113
114    #if defined IMPL_CFA_LL
115      #define DECLS \
116        string_res initval = "starter"; \
117        string_res accum = { initval, COPY_VALUE };
118    #else
119      #define DECLS \
120        string initval = "starter"; \
121        string accum = initval;
122    #endif
123
124    #if defined ALLOC_REUSE
125      DECLS
126      #define RESET \
127        accum = initval;
128    #elif defined ALLOC_FRESH
129      #define RESET \
130        DECLS
131    #else
132      #error bad alloc
133    #endif
134
135    start = clock();
136    end_target = start + CLOCKS_PER_SEC * execTimeSecs;
137    volatile unsigned int t = 0;
138    for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
139            RESET
140            for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
141              MAYBE( PRINT(accum) )
142              char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
143              #if defined OP_PTA && defined IMPL_CFA_LL
144                 pta_ll_temp = accum;
145                 pta_ll_temp += toAppend;
146                 accum = pta_ll_temp;
147              #elif defined OP_PTA
148                 accum = accum + toAppend;
149              #elif defined OP_PEQ
150                 accum += toAppend;
151              #endif
152            }
153    }
154    end_actual = clock();
155    unsigned int concatsDone = t * concatsPerReset;
156    double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
157    printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
158
159    return 0;
160}
Note: See TracBrowser for help on using the repository browser.