Skip to content

Commit

Permalink
Fizz multi buffer benchmark
Browse files Browse the repository at this point in the history
Summary: Fizz multi buffer benchmark

Reviewed By: mingtaoy

Differential Revision: D23886438

fbshipit-source-id: 6cd2b97d848054ab79594d14607bd79208561356
  • Loading branch information
dmm-fb authored and facebook-github-bot committed Sep 24, 2020
1 parent ca39ffb commit 22e7497
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions fizz/record/test/EncryptedRecordBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using namespace fizz;

std::unique_ptr<folly::IOBuf> makeRandom(size_t n) {
std::unique_ptr<folly::IOBuf> makeRandomOne(size_t n) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand All @@ -28,6 +28,27 @@ std::unique_ptr<folly::IOBuf> makeRandom(size_t n) {
return folly::IOBuf::copyBuffer(rv, 5, 17);
}

std::unique_ptr<folly::IOBuf> makeRandom(size_t n, size_t num = 1) {
std::unique_ptr<folly::IOBuf> ret;
size_t one = n/num;
if (!one) {
one = 1;
}

while (n) {
size_t curr = (n > one)?one:n;
auto buf = makeRandomOne(curr);
if (!ret) {
ret = std::move(buf);
}else {
ret->prependChain(std::move(buf));
}

n -= curr;
}
return ret;
}

std::unique_ptr<folly::IOBuf> toIOBuf(std::string hexData) {
std::string out;
CHECK(folly::unhexlify(hexData, out));
Expand All @@ -41,7 +62,7 @@ TrafficKey getKey() {
return trafficKey;
}

void encryptGCM(uint32_t n, size_t size) {
void encryptGCM(uint32_t n, size_t size, size_t num) {
std::unique_ptr<Aead> aead;
std::vector<fizz::TLSMessage> msgs;
EncryptedWriteRecordLayer write{EncryptionLevel::AppTraffic};
Expand All @@ -50,7 +71,7 @@ void encryptGCM(uint32_t n, size_t size) {
aead->setKey(getKey());
write.setAead(folly::ByteRange(), std::move(aead));
for (size_t i = 0; i < n; ++i) {
TLSMessage msg{ContentType::application_data, makeRandom(size)};
TLSMessage msg{ContentType::application_data, makeRandom(size, num)};
msgs.push_back(std::move(msg));
}
}
Expand Down Expand Up @@ -130,11 +151,23 @@ void touchEveryByte(uint32_t n, size_t size) {
folly::doNotOptimizeAway(isTrue);
}

BENCHMARK_PARAM(encryptGCM, 10);
BENCHMARK_PARAM(encryptGCM, 100);
BENCHMARK_PARAM(encryptGCM, 1000);
BENCHMARK_PARAM(encryptGCM, 4000);
BENCHMARK_PARAM(encryptGCM, 8000);
BENCHMARK_NAMED_PARAM(encryptGCM, 10_1, 10, 1);
BENCHMARK_NAMED_PARAM(encryptGCM, 100_1, 100, 1);
BENCHMARK_NAMED_PARAM(encryptGCM, 1000_1, 1000, 1);
BENCHMARK_NAMED_PARAM(encryptGCM, 4000_1, 4000, 1);
BENCHMARK_NAMED_PARAM(encryptGCM, 8000_1, 8000, 1);

BENCHMARK_NAMED_PARAM(encryptGCM, 10_2, 10, 2);
BENCHMARK_NAMED_PARAM(encryptGCM, 100_2, 100, 2);
BENCHMARK_NAMED_PARAM(encryptGCM, 1000_2, 1000, 2);
BENCHMARK_NAMED_PARAM(encryptGCM, 4000_2, 4000, 2);
BENCHMARK_NAMED_PARAM(encryptGCM, 8000_2, 8000, 2);

BENCHMARK_NAMED_PARAM(encryptGCM, 10_4, 10, 4);
BENCHMARK_NAMED_PARAM(encryptGCM, 100_4, 100, 4);
BENCHMARK_NAMED_PARAM(encryptGCM, 1000_4, 1000, 4);
BENCHMARK_NAMED_PARAM(encryptGCM, 4000_4, 4000, 4);
BENCHMARK_NAMED_PARAM(encryptGCM, 8000_4, 8000, 4);

BENCHMARK_PARAM(decryptGCM, 10);
BENCHMARK_PARAM(decryptGCM, 1000);
Expand Down

0 comments on commit 22e7497

Please sign in to comment.