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/io/IOBuf.h>
19 #include <folly/Benchmark.h>
20 #include <folly/Format.h>
21 #include <folly/Range.h>
22 #include <folly/io/Cursor.h>
24 DECLARE_bool(benchmark);
26 using folly::ByteRange;
29 using folly::StringPiece;
30 using std::unique_ptr;
31 using namespace folly::io;
33 int benchmark_size = 1000;
34 unique_ptr<IOBuf> iobuf_benchmark;
36 unique_ptr<IOBuf> iobuf_read_benchmark;
38 template <class CursClass>
40 CursClass c(iobuf_benchmark.get());
42 for (int i = 0; i < benchmark_size; i++) {
47 BENCHMARK(rwPrivateCursorBenchmark, iters) {
49 runBenchmark<RWPrivateCursor>();
53 BENCHMARK(rwUnshareCursorBenchmark, iters) {
55 runBenchmark<RWUnshareCursor>();
59 BENCHMARK(cursorBenchmark, iters) {
61 Cursor c(iobuf_read_benchmark.get());
62 for (int i = 0; i < benchmark_size; i++) {
68 BENCHMARK(skipBenchmark, iters) {
70 Cursor c(iobuf_read_benchmark.get());
71 for (int i = 0; i < benchmark_size; i++) {
78 BENCHMARK(cloneBenchmark, iters) {
81 Cursor c(iobuf_read_benchmark.get());
82 for (int i = 0; i < benchmark_size; ++i) {
89 // _bin/folly/experimental/io/test/iobuf_cursor_test -benchmark
91 // Benchmark Iters Total t t/iter iter/sec
92 // ---------------------------------------------------------------------------
93 // rwPrivateCursorBenchmark 100000 142.9 ms 1.429 us 683.5 k
94 // rwUnshareCursorBenchmark 100000 309.3 ms 3.093 us 315.7 k
95 // cursorBenchmark 100000 741.4 ms 7.414 us 131.7 k
96 // skipBenchmark 100000 738.9 ms 7.389 us 132.2 k
100 // Linux dev2159.snc6.facebook.com 2.6.33-7_fbk15_104e4d0 #1 SMP
101 // Tue Oct 19 22:40:30 PDT 2010 x86_64 x86_64 x86_64 GNU/Linux
103 // 72GB RAM, 2 CPUs (Intel(R) Xeon(R) CPU L5630 @ 2.13GHz)
104 // hyperthreading disabled
106 int main(int argc, char** argv) {
107 gflags::ParseCommandLineFlags(&argc, &argv, true);
108 iobuf_benchmark = IOBuf::create(benchmark_size);
109 iobuf_benchmark->append(benchmark_size);
111 iobuf_read_benchmark = IOBuf::create(1);
112 for (int i = 0; i < benchmark_size; i++) {
113 unique_ptr<IOBuf> iobuf2(IOBuf::create(1));
115 iobuf_read_benchmark->prependChain(std::move(iobuf2));
118 folly::runBenchmarks();