proxygen
ParallelBenchmark.cpp File Reference
#include <array>
#include <future>
#include <iostream>
#include <vector>
#include <glog/logging.h>
#include <folly/gen/Base.h>
#include <folly/gen/Parallel.h>
#include <folly/gen/test/Bench.h>

Go to the source code of this file.

Functions

 DEFINE_int32 (threads, std::max(1,(int32_t) sysconf(_SC_NPROCESSORS_CONF)/2),"Num threads.")
 
size_t fib (int n)
 
static auto stopc (int n)
 
static auto divides (int n)
 
 BENCH_GEN (small|map(factorsSlow)|sum)
 
 BENCH_GEN_REL (small|parallel(map(factorsSlow))|sum)
 
 BENCHMARK_DRAW_LINE ()
 
 BENCH_GEN (small|map(factors)|sum)
 
 BENCH_GEN_REL (small|parallel(map(factors))|sum)
 
 BENCH_GEN (large|map(factors)|sum)
 
 BENCH_GEN_REL (large|parallel(map(factors))|sum)
 
 BENCH_GEN (huge|filter(isPrime)|count)
 
 BENCH_GEN_REL (ch|cat|filter(isPrime)|count)
 
 BENCH_GEN_REL (ch|parallel(cat|filter(isPrime))|count)
 
 BENCH_GEN_REL (ch|parallel(cat|filter(isPrime)|sub(count))|sum)
 
 BENCH_GEN (small|map(sleepAndWork)|sum)
 
 BENCH_GEN_REL (small|parallel(map(sleepAndWork))|sum)
 
 BENCH_GEN (seq(1, fibs)|map([](int){return fib(kFib);})|sum)
 
 BENCH_GEN_REL (seq(1, fibs)|parallel(map([](int){return fib(kFib);})|sub(sum))|sum)
 
 BENCH_GEN_REL ([]{auto threads=seq(1, int(FLAGS_threads))|map([](int i){return std::thread([=]{return range((i+0)*fibs/FLAGS_threads,(i+1)*fibs/FLAGS_threads)|map([](int){return fib(kFib);})|sum;});})|as< vector >();from(threads)|[](std::thread &thread){thread.join();};return 1;}())
 
int main (int argc, char *argv[])
 

Variables

constexpr int kFib = 28
 
static auto isPrimeSlow
 
static auto primes = seq(1, 1 << 20) | filter(isPrimeSlow) | as<vector>()
 
static auto isPrime
 
static auto factors
 
static auto factorsSlow
 
static auto sleepyWork
 
static auto sleepAndWork = [](int i) { return factorsSlow(i) + sleepyWork(i); }
 
auto start = 1 << 20
 
auto v = seq(start) | take(1 << 20) | as<vector>()
 
auto small = from(v) | take(1 << 12)
 
auto medium = from(v) | take(1 << 14)
 
auto large = from(v) | take(1 << 18)
 
auto huge = from(v)
 
auto chunks = chunked(v)
 
auto ch = chunks
 
auto cat = concat
 
const int fibs = 1000
 

Function Documentation

BENCH_GEN ( small|map(factorsSlow)|  sum)
BENCH_GEN ( small|map(factors)|  sum)
BENCH_GEN ( large|map(factors)|  sum)
BENCH_GEN ( huge|filter(isPrime)|  count)
BENCH_GEN ( small|map(sleepAndWork)|  sum)
BENCH_GEN ( seq(1, fibs)|map([](int){return fib(kFib);})|  sum)
BENCH_GEN_REL ( small|parallel(map(factorsSlow))|  sum)
BENCH_GEN_REL ( small|parallel(map(factors))|  sum)
BENCH_GEN_REL ( large|parallel(map(factors))|  sum)
BENCH_GEN_REL ( ch|cat|filter(isPrime)|  count)
BENCH_GEN_REL ( ch|parallel(cat|filter(isPrime))|  count)
BENCH_GEN_REL ( ch|parallel(cat|filter(isPrime)|sub(count))|  sum)
BENCH_GEN_REL ( small|parallel(map(sleepAndWork))|  sum)
BENCH_GEN_REL ( seq(1, fibs)|parallel(map([](int){return fib(kFib);})|sub(sum))|  sum)
BENCH_GEN_REL ( [] {auto threads seq1, int(FLAGS_threads))|map([](int i){return std::thread([=]{return range((i+0)*fibs/FLAGS_threads,(i+1)*fibs/FLAGS_threads)|map([](int){return fib(kFib);})|sum;});})|as< vector >();from(threads)|[](std::thread &thread){thread.join();};return 1;}()
BENCHMARK_DRAW_LINE ( )
DEFINE_int32 ( threads  ,
std::max(1,(int32_t) sysconf(_SC_NPROCESSORS_CONF)/2)  ,
"Num threads."   
)
static auto divides ( int  n)
static

Definition at line 59 of file ParallelBenchmark.cpp.

59  {
60  return [=](int d) { return 0 == n % d; };
61 }
size_t fib ( int  n)

Definition at line 37 of file ParallelBenchmark.cpp.

Referenced by BENCHMARK(), and BENCHMARK_RELATIVE().

37  {
38  return n <= 1 ? 1 : fib(n - 1) + fib(n - 2);
39 }
size_t fib(int n)
int main ( int  argc,
char *  argv[] 
)

Definition at line 168 of file ParallelBenchmark.cpp.

References folly::runBenchmarks().

168  {
169  gflags::ParseCommandLineFlags(&argc, &argv, true);
171  return 0;
172 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
static auto stopc ( int  n)
static

Definition at line 56 of file ParallelBenchmark.cpp.

56  {
57  return [=](int d) { return d * d > n; };
58 }

Variable Documentation

auto cat = concat
auto ch = chunks

Definition at line 103 of file ParallelBenchmark.cpp.

Referenced by folly::BasicFixedString< Char, N >::append(), folly::BasicFixedString< Char, N >::assign(), testing::gmock_matchers_test::AStruct::AStruct(), folly::coro::TimedWaitAwaitable< Awaitable >::await_suspend(), folly::BasicFixedString< Char, N >::BasicFixedString(), testing::gtest_printers_test::Big::Big(), folly::BasicFixedString< Char, N >::cappend(), testing::gmock_generated_actions_test::Char(), testing::gmock_more_actions_test::Char(), folly::BasicFixedString< Char, N >::cpush_back(), proxygen::huffman::HuffTree::encode(), testing::internal::XmlUnitTestResultPrinter::EscapeXml(), testing::internal::XmlUnitTestResultPrinter::EscapeXmlText(), folly::LogStreamBuffer::extractString(), proxygen::huffman::HuffTree::fillIndex(), folly::BasicFixedString< Char, N >::find(), folly::BasicFixedString< Char, N >::find_first_not_of(), folly::BasicFixedString< Char, N >::find_first_of(), folly::BasicFixedString< Char, N >::find_last_not_of(), folly::BasicFixedString< Char, N >::find_last_of(), folly::detail::fixedstring::find_one_of_at_(), proxygen::huffman::HuffTree::getEncodeSize(), testing::internal::GetThreadCount(), testing::internal::GetUnitTestImpl(), folly::hexlify(), proxygen::hexStr(), http_parser_execute(), isLowercase(), testing::internal::IsXDigit(), proxygen::RFC1867Codec::onIngress(), HashTraits::operator()(), folly::BasicFixedString< Char, N >::operator+=(), folly::LogStreamBuffer::overflow(), testing::gmock_generated_actions_test::SubstractAction::Perform(), testing::internal::PortableLocaltime(), testing::internal::PrintColorEncoded(), folly::BasicFixedString< Char, N >::push_back(), proxygen::RFC1867Codec::readToBoundary(), folly::BasicFixedString< Char, N >::replace(), folly::BasicFixedString< Char, N >::resize(), folly::BasicFixedString< Char, N >::rfind(), testing::internal::UnitTestImpl::set_catch_exceptions(), testing::internal::StringStreamToString(), TEST(), testing::gmock_generated_actions_test::TEST(), testing::gmock_more_actions_test::TEST(), testing::gtest_printers_test::TEST(), testing::TEST(), testing::internal::XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(), and testing::gmock_more_actions_test::DeletionTester::~DeletionTester().

auto chunks = chunked(v)

Definition at line 89 of file ParallelBenchmark.cpp.

Referenced by TEST(), TEST_F(), and fizz::test::TEST_P().

auto factors
static
Initial value:
= [](int n) {
return from(primes) | until(stopc(n)) | filter(divides(n)) | count;
}
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
static auto primes
static auto stopc(int n)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count
Until until(Predicate pred=Predicate())
Definition: Base.h:656
static auto divides(int n)

Definition at line 67 of file ParallelBenchmark.cpp.

auto factorsSlow
static
Initial value:
= [](int n) {
return from(primes) | filter(divides(n)) | count;
}
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
static auto primes
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count
static auto divides(int n)

Definition at line 71 of file ParallelBenchmark.cpp.

const int fibs = 1000

Definition at line 115 of file ParallelBenchmark.cpp.

auto huge = from(v)

Definition at line 88 of file ParallelBenchmark.cpp.

Referenced by TEST().

auto isPrime
static
Initial value:
= [](int n) {
return from(primes) | until(stopc(n)) | filter(divides(n)) | isEmpty;
}
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
static auto primes
static auto stopc(int n)
constexpr detail::IsEmpty< true > isEmpty
Definition: Base-inl.h:2555
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
Until until(Predicate pred=Predicate())
Definition: Base.h:656
static auto divides(int n)

Definition at line 63 of file ParallelBenchmark.cpp.

auto isPrimeSlow
static
Initial value:
= [](int n) {
if (n < 2) {
return false;
} else if (n > 2) {
for (int d = 3; d * d <= n; d += 2) {
if (0 == n % d) {
return false;
}
}
}
return true;
}

Definition at line 41 of file ParallelBenchmark.cpp.

constexpr int kFib = 28

Definition at line 36 of file ParallelBenchmark.cpp.

auto large = from(v) | take(1 << 18)

Definition at line 87 of file ParallelBenchmark.cpp.

Referenced by TEST(), and proxygen::TEST_F().

auto medium = from(v) | take(1 << 14)

Definition at line 86 of file ParallelBenchmark.cpp.

auto primes = seq(1, 1 << 20) | filter(isPrimeSlow) | as<vector>()
static

Definition at line 54 of file ParallelBenchmark.cpp.

auto sleepAndWork = [](int i) { return factorsSlow(i) + sleepyWork(i); }
static

Definition at line 81 of file ParallelBenchmark.cpp.

auto sleepyWork
static
Initial value:
= [](int i) {
const auto sleepyTime = std::chrono::microseconds(100);
std::this_thread::sleep_for(sleepyTime);
return i;
}

Definition at line 75 of file ParallelBenchmark.cpp.

auto small = from(v) | take(1 << 12)

Definition at line 85 of file ParallelBenchmark.cpp.

Referenced by TEST(), and proxygen::TEST_F().

auto start = 1 << 20

Definition at line 83 of file ParallelBenchmark.cpp.

Referenced by folly::addBenchmark(), folly::Range< unsigned char * >::assign(), folly::MultiLevelTimeSeries< VT, CT >::avg(), folly::BenchmarkSuspender::BenchmarkSuspender(), folly::compression::instructions::Default::bextr(), folly::BucketedTimeSeries< VT, CT >::buckets(), ScopedServerTest::createScopedServer(), testing::internal::edit_distance::CreateUnifiedDiff(), folly::BenchmarkSuspender::dismiss(), folly::fbvector< HTTPHeaderCode >::do_real_insert(), folly::BucketedTimeSeries< VT, CT >::elapsed(), folly::fbvector< HTTPHeaderCode >::emplace(), folly::test::fc_test(), folly::symbolizer::Dwarf::findDebugInfoOffset(), folly::recordio_helpers::findRecord(), wangle::FizzAcceptorHandshakeHelper::FizzAcceptorHandshakeHelper(), folly::AsyncFileWriter::flush(), funcHasDuration(), folly::MultiLevelTimeSeries< VT, CT >::getLevel(), folly::symbolizer::ElfFile::getSectionByName(), handwrittenAtoi(), folly::MemoryMapping::init(), folly::fbvector< HTTPHeaderCode >::insert(), folly::symbolizer::ElfFile::iterateStrings(), liveClockWaitUntilTests(), FreeDigest::merge(), proxygen::microsecondsBetween(), proxygen::millisecondsBetween(), multiAttemptExpectDurationWithin(), folly::BenchmarkSuspender::operator=(), proxygen::parse(), proxygen::parseUnidirectional(), AtomicBatchDispatcherTesting::Job::preprocess(), std::chrono::PrintTo(), folly::io::test::RandomDataHolder::RandomDataHolder(), folly::TimeseriesHistogram< T, CT, C >::rate(), folly::MultiLevelTimeSeries< VT, CT >::rate(), folly::RelaxedConcurrentPriorityQueue< T, MayBlock, SupportsSize, PopBatch, ListTargetSize, Mutex, Atom >::regularInsert(), folly::BenchmarkSuspender::rehire(), folly::AsyncServerSocket::RemoteAcceptor::RemoteAcceptor(), folly::Range< unsigned char * >::reset(), testing::TestInfo::Run(), testing::TestCase::Run(), run_once(), testing::internal::UnitTestImpl::RunAllTests(), proxygen::ScopedHTTPServer::start< std::unique_ptr< RequestHandlerFactory > >(), proxygen::secondsBetween(), folly::symbolizer::Dwarf::Section::Section(), proxygen::ScopedHTTPServer::start(), testing::internal::StringStreamToString(), folly::BenchmarkSuspender::tally(), testing::internal::TearDownEnvironment(), folly::test::TEST(), TEST(), folly::TEST(), TEST_F(), testConnectOptWrite(), u64ToAsciiClassic(), folly::symbolizer::ElfFile::validateStringTable(), folly::pushmi::time_source_queue< E, TP, NF, Executor >::value(), folly::pushmi::time_source_shared< E, time_point >::worker(), folly::BenchmarkSuspender::~BenchmarkSuspender(), and SSLCacheClient::~SSLCacheClient().

auto v = seq(start) | take(1 << 20) | as<vector>()

Definition at line 84 of file ParallelBenchmark.cpp.

Referenced by LoggingAlloc< T >::address(), folly::gen::detail::Sample< Random >::Generator< Value, Source, Rand, StorageType >::apply(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::assign(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::assign_if_equal(), basic_test(), bench(), BENCHMARK(), BENCHMARK_RELATIVE(), capacity_test(), folly::cEscape(), folly::clamp(), codeSize_bracket_F14Node(), codeSize_bracket_F14Value(), codeSize_bracket_F14Vector(), codeSize_bracket_Std(), folly::collectN(), folly::gen::detail::FileWriter::compose(), folly::gen::detail::UnsplitBuffer< Delimiter, OutputBuffer >::compose(), folly::gen::detail::FoldLeft< Seed, Fold >::compose(), folly::gen::detail::First::compose(), folly::gen::detail::Reduce< Reducer >::compose(), folly::gen::detail::Sum::compose(), folly::gen::detail::Min< Selector, Comparer >::compose(), folly::gen::detail::Append< Collection >::compose(), folly::gen::detail::Collect< Collection >::compose(), folly::gen::detail::CollectTemplate< Container, Allocator >::compose(), folly::constexpr_clamp(), folly::AtomicStruct< folly::IndexedMemPool::TaggedPtr, Atom >::decode(), folly::defaulted(), testing::gmock_matchers_test::EMString(), enq_deq_test(), folly::json::escapeStringImpl(), folly::test::fc_test(), fillCtor(), flow_receiver_1_test(), flow_receiver_n_test(), folly::futures::detail::foreach(), folly::futures::detail::foreach_(), folly::dynamic::getDefault(), folly::Singleton< folly::observer_detail::ObserverManager >::getTeardownFunc(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::insert(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::insert_or_assign(), insertFront(), IntArray< M >::IntArray(), folly::detail::invokeForKeyValue(), lifo_test(), linked_test(), main(), folly::make_optional(), move_test(), mt_linked_test(), testing::gtest_printers_test::AllowsGenericStreamingAndImplicitConversionTemplate< T >::operator bool(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator&=(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator+=(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator-=(), folly::f14::operator<<(), operator<<(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator=(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator^=(), folly::test::DeterministicAtomicImpl< T, Schedule, Atom >::operator|=(), peek_test(), folly::DynamicParser::ParserStack::push(), pushBack(), receiver_1_test(), receiver_n_test(), reserve(), folly::DiscriminatedPtr< Types >::set(), folly::MemoryMapping::Options::setGrow(), folly::MemoryMapping::Options::setPageSize(), folly::MemoryMapping::Options::setPrefault(), folly::MemoryMapping::Options::setReadable(), folly::MemoryMapping::Options::setShared(), folly::MemoryMapping::Options::setWritable(), folly::Fingerprint< BITS >::shlor32(), folly::Fingerprint< BITS >::shlor64(), folly::Fingerprint< BITS >::shlor8(), sizeCtor(), folly::test::staticTracepointTestFunc(), folly::detail::type< T >::store(), StringUnsplit_Gen(), test(), TEST(), testing::gtest_printers_test::TEST(), proxygen::TEST_F(), TEST_F(), testing::gmock_matchers_test::TEST_F(), folly::sync_tests::testAcquireLocked(), folly::sync_tests::testAcquireLockedWithConst(), folly::sync_tests::testConcurrency(), folly::sync_tests::testConstCopy(), folly::sync_tests::testDualLocking(), folly::sync_tests::testDualLockingWithConst(), folly::sync_tests::testExchange(), TESTFUN(), folly::sync_tests::testTimed(), folly::sync_tests::testTimedShared(), folly::sync_tests::testTimedSynchronized(), folly::sync_tests::testTimedSynchronizedWithConst(), testUndoAction(), timeout_test(), folly::DynamicBoundedQueue< T, SingleProducer, SingleConsumer, MayBlock, LgSegmentSize, LgAlign, WeightFn, Atom >::tryEnqueueUntilImpl(), folly::DynamicBoundedQueue< T, SingleProducer, SingleConsumer, MayBlock, LgSegmentSize, LgAlign, WeightFn, Atom >::tryEnqueueUntilSlow(), folly::detail::uintToBinary(), folly::detail::uintToHex(), folly::detail::uintToOctal(), folly::f14::TransparentTrackedEqual< Tag >::unwrap(), and folly::uriEscape().