Skip to content

Commit

Permalink
Add helper for generating random bool vectors (#82)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #82

This is used in a couple places.

Reviewed By: adshastri

Differential Revision: D34830908

fbshipit-source-id: 8800332c1221c05874faaa6b7df40ef891205a69
  • Loading branch information
Elliott Lawrence authored and facebook-github-bot committed Mar 16, 2022
1 parent d992c5a commit 884f7ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ class NpBaseObliviousTransferBenchmark : public util::NetworkedBenchmark {
sender_ = factory.create(std::move(agent0));
receiver_ = factory.create(std::move(agent1));

std::random_device rd;
std::mt19937_64 e(rd());
std::uniform_int_distribution<uint8_t> randomChoice(0, 1);

choice_ = std::vector<bool>(size_);
for (auto i = 0; i < size_; ++i) {
choice_[i] = randomChoice(e);
}
choice_ = util::getRandomBoolVector(size_);
}

void runSender() override {
Expand Down Expand Up @@ -213,13 +206,13 @@ class BidirectionObliviousTransferBenchmark : public util::NetworkedBenchmark {
std::make_unique<RcotBasedBidirectionObliviousTransferFactory<bool>>(
1, *agentFactory1_, getRcotFactory());

senderInput0_ = getRandomBoolVector();
senderInput1_ = getRandomBoolVector();
senderChoice_ = getRandomBoolVector();
senderInput0_ = util::getRandomBoolVector(size_);
senderInput1_ = util::getRandomBoolVector(size_);
senderChoice_ = util::getRandomBoolVector(size_);

receiverInput0_ = getRandomBoolVector();
receiverInput1_ = getRandomBoolVector();
receiverChoice_ = getRandomBoolVector();
receiverInput0_ = util::getRandomBoolVector(size_);
receiverInput1_ = util::getRandomBoolVector(size_);
receiverChoice_ = util::getRandomBoolVector(size_);
}

void runSender() override {
Expand All @@ -241,18 +234,6 @@ class BidirectionObliviousTransferBenchmark : public util::NetworkedBenchmark {
getRcotFactory() = 0;

private:
std::vector<bool> getRandomBoolVector() {
std::random_device rd;
std::mt19937_64 e(rd());
std::uniform_int_distribution<uint8_t> randomChoice(0, 1);

auto result = std::vector<bool>(size_);
for (auto i = 0; i < size_; ++i) {
result[i] = randomChoice(e);
}
return result;
}

size_t size_ = 1000000;

std::unique_ptr<communication::IPartyCommunicationAgentFactory>
Expand Down
9 changes: 9 additions & 0 deletions fbpcf/engine/util/test/benchmarks/BenchmarkHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@
#include "fbpcf/engine/communication/IPartyCommunicationAgent.h"
#include "fbpcf/engine/communication/IPartyCommunicationAgentFactory.h"
#include "fbpcf/engine/communication/SocketPartyCommunicationAgentFactory.h"
#include "folly/Random.h"
#include "folly/logging/xlog.h"

namespace fbpcf::engine::util {

inline std::vector<bool> getRandomBoolVector(size_t size) {
auto result = std::vector<bool>(size);
for (auto i = 0; i < size; ++i) {
result[i] = folly::Random::secureOneIn(2);
}
return result;
}

inline std::pair<
std::unique_ptr<communication::IPartyCommunicationAgent>,
std::unique_ptr<communication::IPartyCommunicationAgent>>
Expand Down

0 comments on commit 884f7ad

Please sign in to comment.