diff options
author | Adam Langley <agl@google.com> | 2015-01-16 03:05:41 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-01-16 22:00:17 +0300 |
commit | 543d00692aad6c6f482a18700cadaaa293666bf2 (patch) | |
tree | dd219921bb8a692506f1558d6656a03f9c5e9461 /tool/speed.cc | |
parent | 7f1d5d5932e123d3999453c0cd80c8538d5527c6 (diff) |
Benchmark AEADs with aligned buffers.
This eliminates a source of variability from the benchmarks.
Change-Id: I8ce07bd68e7591f8c5545040b02b96d21609a0e5
Reviewed-on: https://boringssl-review.googlesource.com/2920
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'tool/speed.cc')
-rw-r--r-- | tool/speed.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tool/speed.cc b/tool/speed.cc index 91901102..ab7faed7 100644 --- a/tool/speed.cc +++ b/tool/speed.cc @@ -162,6 +162,25 @@ static bool SpeedRSA(const std::string& key_name, RSA *key) { return true; } +template<typename T> +struct free_functor { + void operator()(T* ptr) { + free(ptr); + } +}; + +#if defined(OPENSSL_WINDOWS) +#define AllocAligned malloc +#else +uint8_t *AllocAligned(size_t size) { + void *ptr; + if (posix_memalign(&ptr, 64, size)) { + abort(); + } + return static_cast<uint8_t*>(ptr); +} +#endif + static bool SpeedAEADChunk(const EVP_AEAD *aead, const std::string &name, size_t chunk_len) { EVP_AEAD_CTX ctx; @@ -173,9 +192,10 @@ static bool SpeedAEADChunk(const EVP_AEAD *aead, const std::string &name, memset(key.get(), 0, key_len); std::unique_ptr<uint8_t[]> nonce(new uint8_t[nonce_len]); memset(nonce.get(), 0, nonce_len); - std::unique_ptr<uint8_t[]> in(new uint8_t[chunk_len]); + std::unique_ptr<uint8_t, free_functor<uint8_t>> in(AllocAligned(chunk_len)); memset(in.get(), 0, chunk_len); - std::unique_ptr<uint8_t[]> out(new uint8_t[chunk_len + overhead_len]); + std::unique_ptr<uint8_t, free_functor<uint8_t>> out( + AllocAligned(chunk_len + overhead_len)); memset(out.get(), 0, chunk_len + overhead_len); if (!EVP_AEAD_CTX_init(&ctx, aead, key.get(), key_len, |