Skip to content

Commit f728185

Browse files
MatzeBmeta-codesync[bot]
authored andcommitted
Document benchmark init requirement
Summary: Document footgun: Using `folly::runBenchmarks()` without calling `folly::Init()` first will run the benchmarks just fine but ignore all the `--bm_*` commandline flags. Reviewed By: yfeldblum Differential Revision: D116830472 fbshipit-source-id: 26ab16b683a2a83c581d7c308129cb42f77e35c5
1 parent f48f482 commit f728185

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

third-party/folly/src/folly/Benchmark.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace folly {
5252

5353
/**
5454
* Runs all benchmarks defined. Usually put in main().
55+
*
56+
* Caution: call folly::Init before runBenchmarks() for command-line benchmark
57+
* flags to have an effect.
5558
*/
5659
void runBenchmarks();
5760

third-party/folly/src/folly/docs/Benchmark.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Using `folly/Benchmark.h` is very simple. Here's an example:
1616

1717
``` Cpp
1818
#include <folly/Benchmark.h>
19+
#include <folly/init/Init.h>
1920
#include <vector>
2021
using namespace std;
2122
using namespace folly;
@@ -33,7 +34,8 @@ Using `folly/Benchmark.h` is very simple. Here's an example:
3334
v.insert(v.end(), i);
3435
}
3536
}
36-
int main() {
37+
int main(int argc, char** argv) {
38+
Init init(&argc, &argv);
3739
runBenchmarks();
3840
}
3941
```
@@ -70,6 +72,7 @@ implicitly `unsigned`. Consider a slightly reworked example:
7072
``` Cpp
7173
#include <folly/Benchmark.h>
7274
#include <folly/container/Foreach.h>
75+
#include <folly/init/Init.h>
7376
#include <vector>
7477
using namespace std;
7578
using namespace folly;
@@ -85,7 +88,8 @@ implicitly `unsigned`. Consider a slightly reworked example:
8588
v.insert(v.end(), i);
8689
}
8790
}
88-
int main() {
91+
int main(int argc, char** argv) {
92+
Init init(&argc, &argv);
8993
runBenchmarks();
9094
}
9195
```
@@ -126,6 +130,7 @@ compares with it:
126130
``` Cpp
127131
#include <folly/Benchmark.h>
128132
#include <folly/container/Foreach.h>
133+
#include <folly/init/Init.h>
129134
#include <vector>
130135
using namespace std;
131136
using namespace folly;
@@ -141,7 +146,8 @@ compares with it:
141146
v.insert(v.end(), i);
142147
}
143148
}
144-
int main() {
149+
int main(int argc, char** argv) {
150+
Init init(&argc, &argv);
145151
runBenchmarks();
146152
}
147153
```

0 commit comments

Comments
 (0)