| 56 | } |
| 57 | |
| 58 | static void bench_decrypt(benchmark::State& state) { |
| 59 | auto bytes = state.range(0); |
| 60 | auto chunks = state.range(1); |
| 61 | auto chunkSize = bytes / chunks; |
| 62 | StreamCipherKey::initializeGlobalRandomTestKey(); |
| 63 | auto key = StreamCipherKey::getGlobalCipherKey(); |
| 64 | auto iv = getRandomIV(); |
| 65 | auto data = getKey(bytes); |
| 66 | auto encrypted = encrypt(key, iv, data.begin(), data.size()); |
| 67 | while (state.KeepRunning()) { |
| 68 | Arena arena; |
| 69 | DecryptionStreamCipher decryptor(key, iv); |
| 70 | for (int chunk = 0; chunk < chunks; ++chunk) { |
| 71 | benchmark::DoNotOptimize( |
| 72 | Standalone<StringRef>(decryptor.decrypt(encrypted.begin() + chunk * chunkSize, chunkSize, arena))); |
| 73 | } |
| 74 | } |
| 75 | state.SetBytesProcessed(bytes * static_cast<long>(state.iterations())); |
| 76 | } |
| 77 | |
| 78 | BENCHMARK(bench_encrypt)->Ranges({ { 1 << 12, 1 << 20 }, { 1, 1 << 12 } }); |
| 79 | BENCHMARK(bench_decrypt)->Ranges({ { 1 << 12, 1 << 20 }, { 1, 1 << 12 } }); |