2 * Copyright 2014 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "folly/Format.h"
19 #include <glog/logging.h>
21 #include "folly/sorted_vector_types.h"
22 #include "folly/Benchmark.h"
26 using folly::sorted_vector_map;
28 sorted_vector_map<int, int> a;
29 sorted_vector_map<int, int> b;
31 BENCHMARK(merge_by_setting, iters) {
33 // copy to match merge benchmark
36 for (const auto& kv : b_cpy) {
37 a_cpy[kv.first] = kv.second;
42 BENCHMARK_RELATIVE(merge, iters) {
51 // Benchmark results on my dev server (Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz)
53 // ============================================================================
54 // folly/test/SortedVectorBenchmark.cpp relative time/iter iters/s
55 // ============================================================================
56 // merge_by_setting 482.01us 2.07K
57 // merge 2809.19% 17.16us 58.28K
58 // ============================================================================
60 int main(int argc, char *argv[]) {
61 google::ParseCommandLineFlags(&argc, &argv, true);
62 for (int i = 0; i < 1000; ++i) {
64 b[2 * i + 1] = 2 * i + 1;
67 folly::runBenchmarks();