ron4fun/HashLib4CPP

Slower speed

Closed this issue · 1 comments

HashLib4CPP is an outstanding library, however, its hashing speed is mediocre.

For example, HashLib4CPP SHA3 is 15% slower compared to Botan without optimization.

Despite the fact that the library cannot be compiled with modern compilers, slow speed may prevent users from using it.

Also, some update would be useful, like usage of std::vector <uint8_t>

Here is the speed test:

#include <iostream>
#include <fstream>
#include <chrono>

#include "botan_all.h"

#include <string.h>

#include "thirdparty/HashLib4CPP/HashLib4CPP.h"

using namespace std;

int main()
{
std::ifstream input_file ("video.mp4", std::ifstream::in | std::ifstream::binary);
std::vector <uint8_t> buf(98088261);
input_file.read(reinterpret_cast <char *> ( buf.data()), buf.size() );

std::unique_ptr Botan::HashFunction hf ( Botan::HashFunction::create("SHA-3") );

std::chrono::high_resolution_clock timer;

std::chrono::time_point beg = timer.now();
hf->update(buf);

std::cout << "\nBotan: " << Botan::hex_encode( hf->final() );
std::cout << "\nElapsed: " << std::chrono::duration_cast std::chrono::milliseconds ( timer.now() - beg ).count() << " ms\n";

IHash hash = HashLib4CPP::Crypto::CreateSHA3_512();

beg = timer.now();

hash->Initialize();
hash->TransformUntyped( reinterpret_cast <char *> ( buf.data()), buf.size() );

std::cout << "\nHashLib4CPP: " << hash->TransformFinal()->ToString();
std::cout << "\nElapsed: " << std::chrono::duration_cast std::chrono::milliseconds ( timer.now() - beg ).count() << " ms\n";

return 0;
}

output:

Botan: EB12511EC425C42941CF1752EB6AF09287D9D0E50E81D4D7DB804885482A2980C66252362D46C263340C411EAC813639705FE605B8F8F83FF0C3C17576BD9047
Elapsed: 479 ms

HashLib4CPP: EB12511EC425C42941CF1752EB6AF09287D9D0E50E81D4D7DB804885482A2980C66252362D46C263340C411EAC813639705FE605B8F8F83FF0C3C17576BD9047
Elapsed: 549 ms

HashLib4CPP was not built with focus on speed but rather adaptability and cleanliness of code. Thank you.