Skip to content

Commit

Permalink
bench against libb2
Browse files Browse the repository at this point in the history
  • Loading branch information
protz committed Apr 20, 2024
1 parent b999846 commit 7becfee
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ include(${PROJECT_SOURCE_DIR}/build/config.cmake)
# Constants used throughout hacl and the build.
include(config/constants.cmake)

# for libb2
include(FindPkgConfig)

# Set system processor to 32-bit.
# Note that this only works on intel for now.
if(CMAKE_C_FLAGS MATCHES ".*-m32.*")
Expand Down Expand Up @@ -525,6 +528,14 @@ if(ENABLE_BENCHMARKS)
target_compile_definitions(${BENCH_NAME} PUBLIC NO_OPENSSL)
endif(ENABLE_OPENSSL_BENCHMARKS)

if(ENABLE_LIBB2_BENCHMARKS)
pkg_check_modules (LIBB2 REQUIRED libb2)
target_link_libraries(${BENCH_NAME} PRIVATE ${LIBB2_LIBRARIES})
target_link_directories(${BENCH_NAME} PRIVATE ${LIBB2_LIBRARY_DIRS})
target_include_directories(${BENCH_NAME} PUBLIC ${LIBB2_INCLUDE_DIRS})
target_compile_options(${BENCH_NAME} PUBLIC ${LIBB2_CFLAGS_OTHER})
endif(ENABLE_LIBB2_BENCHMARKS)

if(ENABLE_LIBTOMCRYPT_BENCHMARKS)
if(DEFINED ENV{LIBTOMCRYPT_HOME})
target_include_directories(${BENCH_NAME} PUBLIC $ENV{LIBTOMCRYPT_HOME}/include/)
Expand Down
57 changes: 57 additions & 0 deletions benchmarks/blake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ BENCHMARK_CAPTURE(OpenSSL_hash_oneshot,
->Setup(DoSetup);
#endif

#ifndef NO_LIBB2
#include <blake2.h>

static void
libb2_blake2b_oneshot(benchmark::State& state)
{
bytes input(state.range(0), 0xAB);

for (auto _ : state)
blake2b(digest2b.data(), (const void*)input.data(), NULL, digest2b.size(), input.size(), 0);
}

BENCHMARK(libb2_blake2b_oneshot)->Setup(DoSetup);
#endif

// -----------------------------------------------------------------------------

static void
Expand Down Expand Up @@ -150,6 +165,19 @@ OpenSSL_blake2b_oneshot_keyed(benchmark::State& state)
BENCHMARK(OpenSSL_blake2b_oneshot_keyed)->Setup(DoSetup);
#endif

#ifndef NO_LIBB2
#include <blake2.h>

static void
libb2_blake2b_oneshot_keyed(benchmark::State& state)
{
for (auto _ : state)
blake2b(digest2b.data(), (const void*)input.data(), (const void*)key.data(), digest2b.size(), input.size(), key.size());
}

BENCHMARK(libb2_blake2b_oneshot_keyed)->Setup(DoSetup);
#endif


// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -209,6 +237,21 @@ BENCHMARK_CAPTURE(OpenSSL_hash_oneshot,
->Setup(DoSetup);
#endif

#ifndef NO_LIBB2
#include <blake2.h>

static void
libb2_blake2s_oneshot(benchmark::State& state)
{
bytes input(state.range(0), 0xAB);

for (auto _ : state)
blake2s(digest2s.data(), (const void*)input.data(), NULL, digest2s.size(), input.size(), 0);
}

BENCHMARK(libb2_blake2s_oneshot)->Setup(DoSetup);
#endif

// -----------------------------------------------------------------------------

static void
Expand Down Expand Up @@ -262,6 +305,20 @@ OpenSSL_blake2s_oneshot_keyed(benchmark::State& state)
BENCHMARK(OpenSSL_blake2s_oneshot_keyed)->Setup(DoSetup);
#endif

#ifndef NO_LIBB2
#include <blake2.h>

static void
libb2_blake2s_oneshot_keyed(benchmark::State& state)
{
for (auto _ : state)
blake2s(digest2s.data(), (const void*)input.data(), (const void*)key.data(), digest2s.size(), input.size(), key.size());
}

BENCHMARK(libb2_blake2s_oneshot_keyed)->Setup(DoSetup);
#endif


// -----------------------------------------------------------------------------

static void
Expand Down
7 changes: 7 additions & 0 deletions mach
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def install(args):
help="Don't build and run OpenSSL benchmarks.",
action="store_true",
),
argument(
"--no-libb2",
help="Don't build and run libb2 benchmarks.",
action="store_true",
),
argument(
"--libtomcrypt",
help="Build and run LibTomCrypt benchmarks.",
Expand Down Expand Up @@ -340,6 +345,8 @@ def build(args):
)
exit(1)
cmake_args.append("-DENABLE_BENCHMARKS=ON")
if not args.no_libb2:
cmake_args.append("-DENABLE_LIBB2_BENCHMARKS=ON")
if not args.no_openssl:
cmake_args.append("-DENABLE_OPENSSL_BENCHMARKS=ON")
if platform.system() == "Darwin":
Expand Down

0 comments on commit 7becfee

Please sign in to comment.