non-throwing, non-allocating exception_wrapper
[folly.git] / folly / test / TimeseriesBenchmark.cpp
1 /*
2  * Copyright 2017 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 #include <folly/stats/BucketedTimeSeries.h>
17 #include <folly/stats/BucketedTimeSeries-defs.h>
18
19 #include <glog/logging.h>
20
21 #include <folly/Benchmark.h>
22
23 using std::chrono::seconds;
24 using folly::BenchmarkSuspender;
25 using folly::BucketedTimeSeries;
26
27 void addValue(unsigned int iters,
28               seconds duration, size_t numBuckets,
29               size_t callsPerSecond) {
30   BenchmarkSuspender suspend;
31   BucketedTimeSeries<int64_t> ts(numBuckets, duration);
32   suspend.dismiss();
33
34   seconds currentTime(1342000000);
35   size_t timeCounter = 0;
36   for (unsigned int n = 0; n < iters; ++n, ++timeCounter) {
37     if (timeCounter >= callsPerSecond) {
38       timeCounter = 0;
39       ++currentTime;
40     }
41     ts.addValue(currentTime, n);
42   }
43 }
44
45 BENCHMARK_NAMED_PARAM(addValue, AllTime_1perSec, seconds(0), 60, 1);
46 BENCHMARK_NAMED_PARAM(addValue, 3600x60_1perSec, seconds(3600), 60, 1);
47 BENCHMARK_NAMED_PARAM(addValue, 600x60_1perSec, seconds(600), 60, 1);
48 BENCHMARK_NAMED_PARAM(addValue, 60x60_1perSec, seconds(60), 60, 1);
49 BENCHMARK_NAMED_PARAM(addValue, 100x10_1perSec, seconds(100), 10, 1);
50 BENCHMARK_NAMED_PARAM(addValue, 71x5_1perSec, seconds(71), 5, 1);
51 BENCHMARK_NAMED_PARAM(addValue, 1x1_1perSec, seconds(1), 1, 1);
52
53 BENCHMARK_DRAW_LINE()
54
55 BENCHMARK_NAMED_PARAM(addValue, AllTime_10perSec, seconds(0), 60, 10);
56 BENCHMARK_NAMED_PARAM(addValue, 3600x60_10perSec, seconds(3600), 60, 10);
57 BENCHMARK_NAMED_PARAM(addValue, 600x60_10perSec, seconds(600), 60, 10);
58 BENCHMARK_NAMED_PARAM(addValue, 60x60_10perSec, seconds(60), 60, 10);
59 BENCHMARK_NAMED_PARAM(addValue, 100x10_10perSec, seconds(100), 10, 10);
60 BENCHMARK_NAMED_PARAM(addValue, 71x5_10perSec, seconds(71), 5, 10);
61 BENCHMARK_NAMED_PARAM(addValue, 1x1_10perSec, seconds(1), 1, 10);
62
63 BENCHMARK_DRAW_LINE()
64
65 BENCHMARK_NAMED_PARAM(addValue, AllTime_100perSec, seconds(0), 60, 100);
66 BENCHMARK_NAMED_PARAM(addValue, 3600x60_100perSec, seconds(3600), 60, 100);
67 BENCHMARK_NAMED_PARAM(addValue, 600x60_100perSec, seconds(600), 60, 100);
68 BENCHMARK_NAMED_PARAM(addValue, 60x60_100perSec, seconds(60), 60, 100);
69 BENCHMARK_NAMED_PARAM(addValue, 100x10_100perSec, seconds(100), 10, 100);
70 BENCHMARK_NAMED_PARAM(addValue, 71x5_100perSec, seconds(71), 5, 100);
71 BENCHMARK_NAMED_PARAM(addValue, 1x1_100perSec, seconds(1), 1, 100);
72
73 int main(int argc, char *argv[]) {
74   gflags::ParseCommandLineFlags(&argc, &argv, true);
75   folly::runBenchmarks();
76   return 0;
77 }