proxygen
FBStringTestBenchmarks.cpp.h File Reference

Go to the source code of this file.

Functions

void BENCHFUN() initRNG (size_t, size_t)
 
void BENCHFUN() defaultCtor (size_t iters, size_t)
 
void BENCHFUN() copyCtor (size_t iters, size_t arg)
 
void BENCHFUN() ctorFromArray (size_t iters, size_t arg)
 
void BENCHFUN() ctorFromTwoPointers (size_t iters, size_t arg)
 
void BENCHFUN() ctorFromChar (size_t iters, size_t arg)
 
void BENCHFUN() assignmentOp (size_t iters, size_t arg)
 
void BENCHFUN() assignmentFill (size_t iters, size_t)
 
void BENCHFUN() resize (size_t iters, size_t arg)
 
void BENCHFUN() findSuccessful (size_t iters, size_t)
 
void BENCHFUN() findUnsuccessful (size_t iters, size_t)
 
void BENCHFUN() equality (size_t iters, size_t arg)
 
void BENCHFUN() replace (size_t iters, size_t arg)
 
void BENCHFUN() push_back (size_t iters, size_t arg)
 
void BENCHFUN() short_append (size_t iters, size_t arg)
 
void BENCHFUN() getline (size_t iters, size_t arg)
 

Function Documentation

void BENCHFUN() assignmentFill ( size_t  iters,
size_t   
)

Definition at line 106 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, s, and STRING.

106  {
107  STRING s;
108  FOR_EACH_RANGE (i, 0, iters) {
109  s = static_cast<char>(i);
110  doNotOptimizeAway(&s);
111  }
112 }
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() assignmentOp ( size_t  iters,
size_t  arg 
)

Definition at line 90 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, randomString(), s, and STRING.

90  {
91  STRING s;
93  randomString(&s, arg);
94  }
95  FOR_EACH_RANGE (i, 0, iters) {
96  STRING s1;
98  randomString(&s1, arg);
99  doNotOptimizeAway(&s1);
100  }
101  s1 = s;
102  }
103 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
void randomString(String *toFill, size_t size=1000)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() copyCtor ( size_t  iters,
size_t  arg 
)

Definition at line 37 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, randomString(), s, and STRING.

37  {
38  STRING s;
40  randomString(&s, arg);
41  }
42  FOR_EACH_RANGE (i, 0, iters) {
43  STRING s1 = s;
44  doNotOptimizeAway(&s1);
45  }
46 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
void randomString(String *toFill, size_t size=1000)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() ctorFromArray ( size_t  iters,
size_t  arg 
)

Definition at line 49 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, randomString(), s, and STRING.

49  {
50  STRING s;
52  randomString(&s, arg);
53  if (s.empty()) {
54  s = "This is rare.";
55  }
56  }
57  FOR_EACH_RANGE (i, 0, iters) {
58  STRING s1(s.data(), s.size());
59  doNotOptimizeAway(&s1);
60  }
61 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
void randomString(String *toFill, size_t size=1000)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() ctorFromChar ( size_t  iters,
size_t  arg 
)

Definition at line 82 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, and STRING.

82  {
83  FOR_EACH_RANGE (i, 0, iters) {
84  STRING s1('a', arg);
85  doNotOptimizeAway(&s1);
86  }
87 }
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() ctorFromTwoPointers ( size_t  iters,
size_t  arg 
)

Definition at line 64 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, s, and STRING.

64  {
65  /* library-local */ static STRING s;
67  if (s.size() < arg) {
68  s.resize(arg);
69  }
70  }
71  FOR_EACH_RANGE (i, 0, iters) {
72  STRING s1(s.begin(), s.end());
73  doNotOptimizeAway(&s1);
74  }
75 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() defaultCtor ( size_t  iters,
size_t   
)

Definition at line 29 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, s, and STRING.

29  {
30  FOR_EACH_RANGE (i, 0, iters) {
31  STRING s[4096];
33  }
34 }
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() equality ( size_t  iters,
size_t  arg 
)

Definition at line 194 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, needle, randomBinaryString(), and STRING.

194  {
195  std::vector<STRING> haystack(arg);
196 
198  for (auto& hay : haystack) {
199  randomBinaryString(&hay, 1024);
200  }
201  }
202 
203  FOR_EACH_RANGE (i, 0, iters) {
204  STRING needle;
205  randomBinaryString(&needle, 1024);
206  doNotOptimizeAway(std::find(haystack.begin(), haystack.end(), needle));
207  }
208 }
const string needle
void randomBinaryString(String *toFill, size_t size=1000)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() findSuccessful ( size_t  iters,
size_t   
)

Definition at line 124 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, random(), s, and STRING.

124  {
125  size_t pos, len;
126  STRING s;
127 
129  // Text courtesy (ahem) of
130  // http://www.psychologytoday.com/blog/career-transitions/200906/
131  // the-dreaded-writing-sample
132  s = "\
133 Even if you've mastered the art of the cover letter and the resume, \
134 another part of the job search process can trip up an otherwise \
135 qualified candidate: the writing sample.\n\
136 \n\
137 Strong writing and communication skills are highly sought after by \
138 most employers. Whether crafting short emails or lengthy annual \
139 reports, many workers use their writing skills every day. And for an \
140 employer seeking proof behind that ubiquitous candidate \
141 phrase,\"excellent communication skills\", a required writing sample \
142 is invaluable.\n\
143 \n\
144 Writing samples need the same care and attention given to cover \
145 letters and resumes. Candidates with otherwise impeccable credentials \
146 are routinely eliminated by a poorly chosen writing sample. Notice I \
147 said \"poorly chosen\" not \"poorly written.\" Because that's the rub: \
148 a writing sample not only reveals the individual's writing skills, it \
149 also offers a peek into what they consider important or relevant for \
150 the position. If you miss that mark with your writing sample, don't \
151 expect to get a call for an interview.";
152 
153  pos = random(0, s.size());
154  len = random(0, s.size() - pos);
155  }
156  FOR_EACH_RANGE (i, 0, iters) {
157  doNotOptimizeAway(s.find(s.data(), pos, len));
158  }
159 }
Integral2 random(Integral1 low, Integral2 up)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() findUnsuccessful ( size_t  iters,
size_t   
)

Definition at line 162 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, s, and STRING.

162  {
163  STRING s, s1;
164 
166  s = "\
167 Even if you've mastered the art of the cover letter and the resume, \
168 another part of the job search process can trip up an otherwise \
169 qualified candidate: the writing sample.\n\
170 \n\
171 Strong writing and communication skills are highly sought after by \
172 most employers. Whether crafting short emails or lengthy annual \
173 reports, many workers use their writing skills every day. And for an \
174 employer seeking proof behind that ubiquitous candidate \
175 phrase,\"excellent communication skills\", a required writing sample \
176 is invaluable.\n\
177 \n\
178 Writing samples need the same care and attention given to cover \
179 letters and resumes. Candidates with otherwise impeccable credentials \
180 are routinely eliminated by a poorly chosen writing sample. Notice I \
181 said \"poorly chosen\" not \"poorly written.\" Because that's the rub: \
182 a writing sample not only reveals the individual's writing skills, it \
183 also offers a peek into what they consider important or relevant for \
184 the position. If you miss that mark with your writing sample, don't \
185 expect to get a call for an interview.";
186 
187  s1 = "So how do you tackle that writing sample request?";
188  }
189 
190  FOR_EACH_RANGE (i, 0, iters) { doNotOptimizeAway(s.find(s1)); }
191 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() getline ( size_t  iters,
size_t  arg 
)

Definition at line 251 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, folly::gen::lines(), randomString(), and STRING.

Referenced by folly::gen::detail::IStreamByLine::apply(), main(), folly::CacheLocality::readFromSysfs(), and TEST().

251  {
252  string lines;
253 
255  string line;
256  FOR_EACH_RANGE (i, 0, 512) {
257  randomString(&line, arg);
258  lines += line;
259  lines += '\n';
260  }
261  }
262 
263  STRING line;
264  while (iters) {
265  std::istringstream is(lines);
266  while (iters && getline(is, line)) {
267  folly::doNotOptimizeAway(line.size());
268  iters--;
269  }
270  }
271 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
void BENCHFUN() getline(size_t iters, size_t arg)
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
S lines(StringPiece source)
Definition: String.h:80
void randomString(String *toFill, size_t size=1000)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() initRNG ( size_t  ,
size_t   
)

This file is supposed to be included from within FBStringTest. Do not use otherwise.

override-include-guard

Definition at line 24 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, and seed.

24  {
25  srand(seed);
26 }
static const int seed
void BENCHFUN() replace ( size_t  iters,
size_t  arg 
)

Definition at line 211 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, random(), randomString(), s, and STRING.

Referenced by folly::basic_fbstring< char >::assign(), testing::internal::edit_distance::CalculateOptimalEdits(), shell_builder.ShellFBCodeBuilder::copy_local_repo(), folly::BasicFixedString< Char, N >::erase(), shell_quoting.ShellQuoted::format(), upload.MercurialVCS::GetBaseFile(), upload.VersionControlSystem::GetBaseFiles(), shell_builder::persistent_temp_dir(), folly::basic_fbstring< char >::replace(), folly::BasicFixedString< Char, N >::replace(), folly::basic_fbstring< E, T, A, Storage >::replaceImplDiscr(), shell_quoting::shell_comment(), shell_quoting::shell_quote(), testing::internal::ShouldRunTestCase(), upload::SplitPatch(), gmock_output_test::ToUnixLineEnding(), and gtest_output_test::ToUnixLineEnding().

211  {
212  STRING s;
214  randomString(&s, arg);
215  }
216  FOR_EACH_RANGE (i, 0, iters) {
217  BenchmarkSuspender susp;
218  doNotOptimizeAway(&s);
219  auto const pos = random(0, s.size());
220  auto toRemove = random(0, s.size() - pos);
221  auto toInsert = random(0, arg);
222  STRING s1;
223  randomString(&s1, toInsert);
224  susp.dismiss();
225 
226  s.replace(pos, toRemove, s1);
227  }
228 }
Integral2 random(Integral1 low, Integral2 up)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
void randomString(String *toFill, size_t size=1000)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() resize ( size_t  iters,
size_t  arg 
)

Definition at line 115 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, random(), s, and STRING.

Referenced by folly::basic_fbstring< E, T, A, Storage >::assign(), folly::basic_fbstring< char >::clear(), folly::basic_fbstring< char >::erase(), folly::basic_fbstring< E, T, A, Storage >::getlineImpl(), folly::basic_fbstring< char >::max_size(), folly::BasicFixedString< Char, N >::resize(), and folly::basic_fbstring< char >::substr().

115  {
116  STRING s;
117  FOR_EACH_RANGE (i, 0, iters) {
118  s.resize(random(0, arg));
119  doNotOptimizeAway(&s);
120  }
121 }
Integral2 random(Integral1 low, Integral2 up)
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void BENCHFUN() short_append ( size_t  iters,
size_t  arg 
)

Definition at line 242 of file FBStringTestBenchmarks.cpp.h.

References BENCHFUN, BENCHMARK_PARAM, FOR_EACH_RANGE, i, s, and STRING.

242  {
243  FOR_EACH_RANGE (i, 0, iters) {
244  STRING s;
245  FOR_EACH_RANGE (j, 0, arg) { s += "012"; }
246  }
247 }
#define STRING
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static set< string > s