Skip to content

Commit

Permalink
Improve crypto benchmark.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ff215ba75a1d7005e13fb73b16f84d59c8365b98
  • Loading branch information
levlam committed Jun 16, 2020
1 parent 96b18f3 commit 86ca096
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions benchmark/bench_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ class AesCbcBench : public td::Benchmark {
}
};

template <bool use_state>
class AesIgeShortBench : public td::Benchmark {
public:
static constexpr int SHORT_DATA_SIZE = 16;
static constexpr int SHORT_DATA_SIZE = 64;
alignas(64) unsigned char data[SHORT_DATA_SIZE];
td::UInt256 key;
td::UInt256 iv;

std::string get_description() const override {
return PSTRING() << "AES IGE OpenSSL [" << SHORT_DATA_SIZE << "B]";
return PSTRING() << "AES IGE OpenSSL " << (use_state ? "EVP" : "C ") << "[" << SHORT_DATA_SIZE << "B]";
}

void start_up() override {
Expand All @@ -212,11 +213,11 @@ class AesIgeShortBench : public td::Benchmark {
td::MutableSlice data_slice(data, SHORT_DATA_SIZE);
td::AesIgeState ige;
for (int i = 0; i < n; i++) {
if (true) {
ige.init(as_slice(key), as_slice(iv), true);
ige.encrypt(data_slice, data_slice);
if (use_state) {
ige.init(as_slice(key), as_slice(iv), false);
ige.decrypt(data_slice, data_slice);
} else {
td::aes_ige_encrypt(as_slice(key), as_slice(iv), data_slice, data_slice);
td::aes_ige_decrypt(as_slice(key), as_slice(iv), data_slice, data_slice);
}
}
}
Expand Down Expand Up @@ -346,7 +347,8 @@ class Crc64Bench : public td::Benchmark {
int main() {
td::init_openssl_threads();

td::bench(AesIgeShortBench());
td::bench(AesIgeShortBench<true>());
td::bench(AesIgeShortBench<false>());
td::bench(AesIgeEncryptBench());
td::bench(AesIgeDecryptBench());
td::bench(AesEcbBench());
Expand Down

0 comments on commit 86ca096

Please sign in to comment.