2 * Copyright 2017 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/Benchmark.h>
18 #include <folly/io/IOBuf.h>
22 BENCHMARK(cloneOneBenchmark, iters) {
23 IOBuf buf(IOBuf::CREATE, 10);
25 auto copy = buf.cloneOne();
26 folly::doNotOptimizeAway(copy->capacity());
30 BENCHMARK(cloneOneIntoBenchmark, iters) {
31 IOBuf buf(IOBuf::CREATE, 10);
34 buf.cloneOneInto(copy);
35 folly::doNotOptimizeAway(copy.capacity());
39 BENCHMARK(cloneBenchmark, iters) {
40 IOBuf buf(IOBuf::CREATE, 10);
42 auto copy = buf.clone();
43 folly::doNotOptimizeAway(copy->capacity());
47 BENCHMARK(cloneIntoBenchmark, iters) {
48 IOBuf buf(IOBuf::CREATE, 10);
52 folly::doNotOptimizeAway(copy.capacity());
56 BENCHMARK(moveBenchmark, iters) {
57 IOBuf buf(IOBuf::CREATE, 10);
59 auto tmp = std::move(buf);
60 folly::doNotOptimizeAway(tmp.capacity());
65 BENCHMARK(copyBenchmark, iters) {
66 IOBuf buf(IOBuf::CREATE, 10);
69 folly::doNotOptimizeAway(copy.capacity());
74 * ============================================================================
75 * folly/io/test/IOBufBenchmark.cpp relative time/iter iters/s
76 * ============================================================================
77 * cloneOneBenchmark 49.03ns 20.39M
78 * cloneOneIntoBenchmark 26.36ns 37.93M
79 * cloneBenchmark 49.43ns 20.23M
80 * cloneIntoBenchmark 30.03ns 33.30M
81 * moveBenchmark 15.35ns 65.14M
82 * copyBenchmark 33.63ns 29.73M
83 * ============================================================================
86 int main(int argc, char** argv) {
87 gflags::ParseCommandLineFlags(&argc, &argv, true);
88 folly::runBenchmarks();