Skip to content

Commit 4c87e42

Browse files
Elliott Lawrencefacebook-github-bot
authored andcommitted
Benchmark for tuple generators (#83)
Summary: Pull Request resolved: #83 Adding benchmarks for the tuple generator and two-party tuple generator. Reviewed By: RuiyuZhu Differential Revision: D34833460 fbshipit-source-id: 700ef5ad205aab55eb6a99e699bbca21ceb58d0d
1 parent 4861c1d commit 4c87e42

3 files changed

Lines changed: 95 additions & 9 deletions

File tree

fbpcf/engine/tuple_generator/test/TupleGeneratorTest.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,14 @@ TEST(TupleGeneratorTest, testWithDummyProductShareGenerator) {
8484
int numberOfParty = 4;
8585

8686
testTupleGenerator(
87-
numberOfParty,
88-
89-
createInMemoryTupleGeneratorFactoryWithDummyProductShareGenerator);
87+
numberOfParty, createTupleGeneratorFactoryWithDummyProductShareGenerator);
9088
}
9189

9290
TEST(TupleGeneratorTest, testWithSecureProductShareGenerator) {
9391
int numberOfParty = 4;
9492

9593
testTupleGenerator(
96-
numberOfParty,
97-
createInMemoryTupleGeneratorFactoryWithRealProductShareGenerator);
94+
numberOfParty, createTupleGeneratorFactoryWithRealProductShareGenerator);
9895
}
9996

10097
TEST(TupleGeneratorTest, testTwoPartyTupleGeneratorWithDummyRcot) {

fbpcf/engine/tuple_generator/test/TupleGeneratorTestHelper.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <memory>
1313

1414
#include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h"
15-
#include "fbpcf/engine/communication/InMemoryPartyCommunicationAgentFactory.h"
16-
#include "fbpcf/engine/communication/InMemoryPartyCommunicationAgentHost.h"
1715
#include "fbpcf/engine/communication/test/AgentFactoryCreationHelper.h"
1816
#include "fbpcf/engine/tuple_generator/DummyProductShareGeneratorFactory.h"
1917
#include "fbpcf/engine/tuple_generator/DummyTupleGeneratorFactory.h"
@@ -54,7 +52,7 @@ inline std::unique_ptr<ITupleGeneratorFactory> createDummyTupleGeneratorFactory(
5452
}
5553

5654
inline std::unique_ptr<ITupleGeneratorFactory>
57-
createInMemoryTupleGeneratorFactoryWithDummyProductShareGenerator(
55+
createTupleGeneratorFactoryWithDummyProductShareGenerator(
5856
int numberOfParty,
5957
int myId,
6058
communication::IPartyCommunicationAgentFactory& agentFactory) {
@@ -69,7 +67,7 @@ createInMemoryTupleGeneratorFactoryWithDummyProductShareGenerator(
6967
}
7068

7169
inline std::unique_ptr<ITupleGeneratorFactory>
72-
createInMemoryTupleGeneratorFactoryWithRealProductShareGenerator(
70+
createTupleGeneratorFactoryWithRealProductShareGenerator(
7371
int numberOfParty,
7472
int myId,
7573
communication::IPartyCommunicationAgentFactory& agentFactory) {

fbpcf/engine/tuple_generator/test/benchmarks/TupleGeneratorBenchmark.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,97 @@ BENCHMARK_COUNTERS(ProductShareGenerator, counters) {
8787
benchmark.runBenchmark(counters);
8888
}
8989

90+
class BaseTupleGeneratorBenchmark : public util::NetworkedBenchmark {
91+
public:
92+
void setup() override {
93+
auto [agentFactory0, agentFactory1] = util::getSocketAgentFactories();
94+
agentFactory0_ = std::move(agentFactory0);
95+
agentFactory1_ = std::move(agentFactory1);
96+
97+
senderFactory_ = getTupleGeneratorFactory(0, *agentFactory0_);
98+
receiverFactory_ = getTupleGeneratorFactory(1, *agentFactory1_);
99+
}
100+
101+
void runSender() override {
102+
sender_ = senderFactory_->create();
103+
sender_->getBooleanTuple(size_);
104+
}
105+
106+
void runReceiver() override {
107+
receiver_ = receiverFactory_->create();
108+
receiver_->getBooleanTuple(size_);
109+
}
110+
111+
std::pair<uint64_t, uint64_t> getTrafficStatistics() override {
112+
return sender_->getTrafficStatistics();
113+
}
114+
115+
protected:
116+
virtual std::unique_ptr<ITupleGeneratorFactory> getTupleGeneratorFactory(
117+
int myId,
118+
communication::IPartyCommunicationAgentFactory& agentFactory) = 0;
119+
120+
size_t bufferSize_ = 1600000;
121+
122+
private:
123+
size_t size_ = 1000000;
124+
125+
std::unique_ptr<communication::IPartyCommunicationAgentFactory>
126+
agentFactory0_;
127+
std::unique_ptr<communication::IPartyCommunicationAgentFactory>
128+
agentFactory1_;
129+
130+
std::unique_ptr<ITupleGeneratorFactory> senderFactory_;
131+
std::unique_ptr<ITupleGeneratorFactory> receiverFactory_;
132+
133+
std::unique_ptr<ITupleGenerator> sender_;
134+
std::unique_ptr<ITupleGenerator> receiver_;
135+
};
136+
137+
class TupleGeneratorBenchmark final : public BaseTupleGeneratorBenchmark {
138+
protected:
139+
std::unique_ptr<ITupleGeneratorFactory> getTupleGeneratorFactory(
140+
int myId,
141+
communication::IPartyCommunicationAgentFactory& agentFactory) override {
142+
auto otFactory = std::make_unique<
143+
oblivious_transfer::RcotBasedBidirectionObliviousTransferFactory<bool>>(
144+
myId, agentFactory, oblivious_transfer::createFerretRcotFactory());
145+
auto productShareGeneratorFactory =
146+
std::make_unique<ProductShareGeneratorFactory<bool>>(
147+
std::make_unique<util::AesPrgFactory>(bufferSize_),
148+
std::move(otFactory));
149+
return std::make_unique<TupleGeneratorFactory>(
150+
std::move(productShareGeneratorFactory),
151+
std::make_unique<util::AesPrgFactory>(),
152+
bufferSize_,
153+
myId,
154+
2);
155+
}
156+
};
157+
158+
BENCHMARK_COUNTERS(TupleGenerator, counters) {
159+
TupleGeneratorBenchmark benchmark;
160+
benchmark.runBenchmark(counters);
161+
}
162+
163+
class TwoPartyTupleGeneratorBenchmark final
164+
: public BaseTupleGeneratorBenchmark {
165+
protected:
166+
std::unique_ptr<ITupleGeneratorFactory> getTupleGeneratorFactory(
167+
int myId,
168+
communication::IPartyCommunicationAgentFactory& agentFactory) override {
169+
return std::make_unique<TwoPartyTupleGeneratorFactory>(
170+
oblivious_transfer::createFerretRcotFactory(),
171+
agentFactory,
172+
myId,
173+
bufferSize_);
174+
}
175+
};
176+
177+
BENCHMARK_COUNTERS(TwoPartyTupleGenerator, counters) {
178+
TwoPartyTupleGeneratorBenchmark benchmark;
179+
benchmark.runBenchmark(counters);
180+
}
90181
} // namespace fbpcf::engine::tuple_generator
91182

92183
int main(int argc, char* argv[]) {

0 commit comments

Comments
 (0)