proxygen
FileBenchmark.cpp File Reference
#include <thread>
#include <glog/logging.h>
#include <folly/Benchmark.h>
#include <folly/File.h>
#include <folly/gen/Base.h>
#include <folly/gen/File.h>

Go to the source code of this file.

Functions

 BENCHMARK (ByLine_Pipes, iters)
 
int main (int argc, char *argv[])
 

Function Documentation

BENCHMARK ( ByLine_Pipes  ,
iters   
)

Definition at line 28 of file FileBenchmark.cpp.

References BENCHMARK_SUSPEND, folly::gen::byLine(), folly::netops::close(), folly::doNotOptimizeAway(), f, FILE, i, int64_t, pipe(), fizz::detail::read(), s, folly::gen::sum, and fizz::detail::write().

28  {
29  std::thread thread;
30  int rfd = -1;
31  int wfd;
33  int p[2];
34  CHECK_ERR(::pipe(p));
35  rfd = p[0];
36  wfd = p[1];
37  thread = std::thread([wfd, iters] {
38  char x = 'x';
39  PCHECK(::write(wfd, &x, 1) == 1); // signal startup
40  FILE* f = fdopen(wfd, "w");
41  PCHECK(f);
42  for (size_t i = 1; i <= iters; ++i) {
43  fprintf(f, "%zu\n", i);
44  }
45  fclose(f);
46  });
47  char buf;
48  PCHECK(::read(rfd, &buf, 1) == 1); // wait for startup
49  }
50 
51  CHECK_ERR(rfd);
52  auto s = byLine(folly::File(rfd)) | eachTo<int64_t>() | sum;
54 
56  ::close(rfd);
57  CHECK_EQ(s, int64_t(iters) * (iters + 1) / 2);
58  thread.join();
59  }
60 }
Definition: InvokeTest.cpp:58
auto f
std::atomic< int64_t > sum(0)
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
auto byLine(File file, char delim= '\n')
Definition: File-inl.h:148
static set< string > s
int close(NetworkSocket s)
Definition: NetOps.cpp:90
GMockOutputTest ExpectedCall FILE
void pipe(CPUExecutor cpu, IOExecutor io)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char *  argv[] 
)

Definition at line 69 of file FileBenchmark.cpp.

References folly::runBenchmarks().

69  {
70  gflags::ParseCommandLineFlags(&argc, &argv, true);
72  return 0;
73 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv