source: tests/zombies/string-perf/pbx-correctness-demos.cpp@ f1d2c44

Last change on this file since f1d2c44 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.0 KB
Line 
1// see also C++ investigation in ~/plg2/cfa2/mycode/string/raii/ctor-calls.cpp
2
3#include <string>
4#include <iostream>
5
6using namespace std;
7
8#define HELPER_BODY(param) \
9 cout << "early in helper with " << param << endl; \
10 param[0] = '+'; \
11 cout << "late in helper with " << param << endl;
12
13void helper1( string q ) { HELPER_BODY(q) }
14void helper2( string & q ) { HELPER_BODY(q) }
15#undef HELPER_BODY
16
17
18void calltest_HL() {
19
20 string fred;
21
22
23 cout << "===" << endl;
24 cout << "HL: substring of part" << endl;
25
26 cout << "---" << endl;
27 // Calling a by-val function, the only way it supports, in which it gets a private logical copy.
28 fred = "abcd";
29 cout << "before helper with " << fred << endl;
30 helper1( fred.substr(1,3) );
31 cout << "after helper with " << fred << endl;
32
33 cout << "---" << endl;
34 // Calling a by-ref function, catching side effects the only place STL-string gives them, in an explicit copy.
35 fred = "abcd";
36 cout << "before helper with " << fred << endl;
37 {
38 string fred_sub = fred.substr(1,3);
39 helper2( fred_sub );
40 cout << "after helper with temp having " << fred_sub << endl;
41 }
42 cout << "after helper with original having " << fred << endl;
43
44
45 cout << "===" << endl;
46 cout << "HL: substring of whole" << endl;
47
48 cout << "---" << endl;
49 // Calling a by-val function, the only way it supports, in which it gets a private logical copy.
50 fred = "abcd";
51 cout << "before helper with " << fred << endl;
52 helper1( fred.substr(0,4) );
53 cout << "after helper with " << fred << endl;
54
55 cout << "---" << endl;
56 // Calling a by-ref function, catching side effects the only place STL-string gives them, in an explicit copy.
57 fred = "abcd";
58 cout << "before helper with " << fred << endl;
59 {
60 string fred_sub = fred.substr(0,4);
61 helper2( fred_sub );
62 cout << "after helper with temp having " << fred_sub << endl;
63 }
64 cout << "after helper with original having " << fred << endl;
65
66
67
68 cout << "===" << endl;
69 cout << "HL: whole original string" << endl;
70
71 cout << "---" << endl;
72 // Calling a by-val function, the only way it supports, in which it gets a private logical copy.
73 fred = "abcd";
74 cout << "before helper with " << fred << endl;
75 helper1( fred );
76 cout << "after helper with " << fred << endl;
77
78 cout << "---" << endl;
79 // Calling a by-ref function, sys-style, in which we want to gets its changes as side effects.
80 fred = "abcd";
81 cout << "before helper with " << fred << endl;
82 helper2( fred );
83 cout << "after helper with " << fred << endl;
84
85 cout << "---" << endl;
86 // Calling a by-ref function, trans-style, in which we give it a logical copy, to prevent it from pulluting our gold one; copy needs explicit variable.
87 fred = "abcd";
88 cout << "before helper with " << fred << endl;
89 {
90 string fred_cpy = fred;
91 helper2( fred_cpy );
92 }
93 cout << "after helper with " << fred << endl;
94}
95
96
97
98int main() {
99
100 calltest_HL();
101
102}
Note: See TracBrowser for help on using the repository browser.