bryancall commented on pull request #8615:
URL: https://github.com/apache/trafficserver/pull/8615#issuecomment-1016788699
@maskit There is no performance difference between the old and new APIs. I
am shocked that there would be a difference with the SHA functions.
```
11:07:37 zeus:(master)~/files/src/c/test_code$ g++ benchmark_openssl_md5.cc
-lbenchmark -lssl -lcrypto && ./a.out
2022-01-19T11:08:04-08:00
Running ./a.out
Run on (24 X 4672.07 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x12)
L1 Instruction 32 KiB (x12)
L2 Unified 512 KiB (x12)
L3 Unified 16384 KiB (x4)
Load Average: 0.17, 0.28, 0.22
***WARNING*** CPU scaling is enabled, the benchmark real time measurements
may be noisy and will incur extra overhead.
--------------------------------------------------------
Benchmark Time CPU Iterations
--------------------------------------------------------
openssl_1_md5 1238 ns 1236 ns 566867
openssl_3_md5 1240 ns 1238 ns 565212
```
Here is my benchmark code:
```
#include <iostream>
#include <string>
#include <string_view>
#include <openssl/evp.h>
#include <openssl/md5.h>
#include <benchmark/benchmark.h>
//-----------------------------------------------------------------------------
class Data {
public:
Data() {
_data.reserve(_size);
for (int i = 0; i < _size; i++) {
_data.push_back((char)rand() % 256);
}
}
void reset() {
_position = 0;
}
std::string_view read() {
if (_position + 1024 > _size) {
_position = 0;
}
std::string_view tmp = _data.substr(_position, 1024);
_position += 1024;
return tmp;
}
private:
std::string _data;
static constexpr size_t _size = 1 << 20;
size_t _position = 0;
};
Data data;
//-----------------------------------------------------------------------------
class MD5_openssl1
{
private:
MD5_CTX _ctx;
unsigned char _hash[MD5_DIGEST_LENGTH];
public:
MD5_openssl1()
{
MD5_Init(&_ctx);
}
bool update(void const *data, int length)
{
return 0 != MD5_Update(&_ctx, data, length);
}
unsigned char *finalize()
{
MD5_Final(_hash, &_ctx);
return _hash;
}
};
//-----------------------------------------------------------------------------
class MD5_openssl3
{
protected:
EVP_MD_CTX *_ctx = nullptr;
unsigned char _hash[MD5_DIGEST_LENGTH];
public:
MD5_openssl3()
{
_ctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(_ctx, EVP_md5(), nullptr);
}
~MD5_openssl3() { EVP_MD_CTX_free(_ctx); }
bool update(void const *data, int length)
{
return EVP_DigestUpdate(_ctx, data, length);
}
unsigned char *finalize()
{
EVP_DigestFinal_ex(_ctx, _hash, nullptr);
return _hash;
}
};
//-----------------------------------------------------------------------------
static void openssl_1_md5(benchmark::State& state) {
MD5_openssl1 md5;
data.reset();
for (auto _ : state) {
std::string_view tmp = data.read();
md5.update(tmp.data(), tmp.size());
}
}
//-----------------------------------------------------------------------------
static void openssl_3_md5(benchmark::State& state) {
MD5_openssl3 md5;
data.reset();
for (auto _ : state) {
std::string_view tmp = data.read();
md5.update(tmp.data(), tmp.size());
}
}
//-----------------------------------------------------------------------------
BENCHMARK(openssl_1_md5);
BENCHMARK(openssl_3_md5);
BENCHMARK_MAIN();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]