proxygen
BucketedTimeSeriesBenchmark.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <glog/logging.h>
20 
21 #include <folly/Benchmark.h>
23 
26 using std::chrono::seconds;
27 
28 void addValue(
29  unsigned int iters,
30  seconds duration,
31  size_t numBuckets,
32  size_t callsPerSecond) {
33  BenchmarkSuspender suspend;
34  BucketedTimeSeries<int64_t> ts(numBuckets, duration);
35  suspend.dismiss();
36 
37  seconds currentTime(1342000000);
38  size_t timeCounter = 0;
39  for (unsigned int n = 0; n < iters; ++n, ++timeCounter) {
40  if (timeCounter >= callsPerSecond) {
41  timeCounter = 0;
42  ++currentTime;
43  }
44  ts.addValue(currentTime, n);
45  }
46 }
47 
48 BENCHMARK_NAMED_PARAM(addValue, AllTime_1perSec, seconds(0), 60, 1)
49 BENCHMARK_NAMED_PARAM(addValue, 3600x60_1perSec, seconds(3600), 60, 1)
50 BENCHMARK_NAMED_PARAM(addValue, 600x60_1perSec, seconds(600), 60, 1)
51 BENCHMARK_NAMED_PARAM(addValue, 60x60_1perSec, seconds(60), 60, 1)
52 BENCHMARK_NAMED_PARAM(addValue, 100x10_1perSec, seconds(100), 10, 1)
53 BENCHMARK_NAMED_PARAM(addValue, 71x5_1perSec, seconds(71), 5, 1)
54 BENCHMARK_NAMED_PARAM(addValue, 1x1_1perSec, seconds(1), 1, 1)
55 
57 
58 BENCHMARK_NAMED_PARAM(addValue, AllTime_10perSec, seconds(0), 60, 10)
59 BENCHMARK_NAMED_PARAM(addValue, 3600x60_10perSec, seconds(3600), 60, 10)
60 BENCHMARK_NAMED_PARAM(addValue, 600x60_10perSec, seconds(600), 60, 10)
61 BENCHMARK_NAMED_PARAM(addValue, 60x60_10perSec, seconds(60), 60, 10)
62 BENCHMARK_NAMED_PARAM(addValue, 100x10_10perSec, seconds(100), 10, 10)
63 BENCHMARK_NAMED_PARAM(addValue, 71x5_10perSec, seconds(71), 5, 10)
64 BENCHMARK_NAMED_PARAM(addValue, 1x1_10perSec, seconds(1), 1, 10)
65 
67 
68 BENCHMARK_NAMED_PARAM(addValue, AllTime_100perSec, seconds(0), 60, 100)
69 BENCHMARK_NAMED_PARAM(addValue, 3600x60_100perSec, seconds(3600), 60, 100)
70 BENCHMARK_NAMED_PARAM(addValue, 600x60_100perSec, seconds(600), 60, 100)
71 BENCHMARK_NAMED_PARAM(addValue, 60x60_100perSec, seconds(60), 60, 100)
72 BENCHMARK_NAMED_PARAM(addValue, 100x10_100perSec, seconds(100), 10, 100)
73 BENCHMARK_NAMED_PARAM(addValue, 71x5_100perSec, seconds(71), 5, 100)
74 BENCHMARK_NAMED_PARAM(addValue, 1x1_100perSec, seconds(1), 1, 100)
75 
76 int main(int argc, char* argv[]) {
77  gflags::ParseCommandLineFlags(&argc, &argv, true);
79  return 0;
80 }
int main(int argc, char *argv[])
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
#define BENCHMARK_NAMED_PARAM(name, param_name,...)
Definition: Benchmark.h:449
bool addValue(TimePoint now, const ValueType &val)
BENCHMARK_DRAW_LINE()
void addValue(unsigned int iters, seconds duration, size_t numBuckets, size_t callsPerSecond)