2 * Copyright 2016 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>
23 #include <folly/io/Cursor-defs.h>
25 DECLARE_bool(benchmark);
27 using folly::ByteRange;
30 using folly::StringPiece;
31 using std::unique_ptr;
32 using namespace folly::io;
34 int benchmark_size = 1000;
35 unique_ptr<IOBuf> iobuf_benchmark;
37 unique_ptr<IOBuf> iobuf_read_benchmark;
39 template <class CursClass>
41 CursClass c(iobuf_benchmark.get());
43 for (int i = 0; i < benchmark_size; i++) {
48 BENCHMARK(rwPrivateCursorBenchmark, iters) {
50 runBenchmark<RWPrivateCursor>();
54 BENCHMARK(rwUnshareCursorBenchmark, iters) {
56 runBenchmark<RWUnshareCursor>();
60 BENCHMARK(cursorBenchmark, iters) {
62 Cursor c(iobuf_read_benchmark.get());
63 for (int i = 0; i < benchmark_size; i++) {
69 BENCHMARK(skipBenchmark, iters) {
71 Cursor c(iobuf_read_benchmark.get());
72 for (int i = 0; i < benchmark_size; i++) {
80 // _bin/folly/experimental/io/test/iobuf_cursor_test -benchmark
82 // Benchmark Iters Total t t/iter iter/sec
83 // ---------------------------------------------------------------------------
84 // rwPrivateCursorBenchmark 100000 142.9 ms 1.429 us 683.5 k
85 // rwUnshareCursorBenchmark 100000 309.3 ms 3.093 us 315.7 k
86 // cursorBenchmark 100000 741.4 ms 7.414 us 131.7 k
87 // skipBenchmark 100000 738.9 ms 7.389 us 132.2 k
91 // Linux dev2159.snc6.facebook.com 2.6.33-7_fbk15_104e4d0 #1 SMP
92 // Tue Oct 19 22:40:30 PDT 2010 x86_64 x86_64 x86_64 GNU/Linux
94 // 72GB RAM, 2 CPUs (Intel(R) Xeon(R) CPU L5630 @ 2.13GHz)
95 // hyperthreading disabled
97 int main(int argc, char** argv) {
98 gflags::ParseCommandLineFlags(&argc, &argv, true);
99 iobuf_benchmark = IOBuf::create(benchmark_size);
100 iobuf_benchmark->append(benchmark_size);
102 iobuf_read_benchmark = IOBuf::create(1);
103 for (int i = 0; i < benchmark_size; i++) {
104 unique_ptr<IOBuf> iobuf2(IOBuf::create(1));
106 iobuf_read_benchmark->prependChain(std::move(iobuf2));
109 folly::runBenchmarks();