Skip to content

Commit

Permalink
use cpucycles
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Dec 15, 2024
1 parent f234be2 commit 25e86ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ endif()

project(SMHasher C CXX ASM)

# cat https://cpucycles.cr.yp.to/libcpucycles-latest-version.txt
set(libcpucycle_version 20240318)
include(ExternalProject)
# libcpucycle-prefix/src/libcpucycle/build/amd64/package/lib/libcpucycles.a
# => lib/libcpucycles.a
ExternalProject_Add(
libcpucycle
URL https://cpucycles.cr.yp.to/libcpucycles-${libcpucycle_version}.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP false
#PREFIX ""
BINARY_DIR libcpucycle-prefix/src/libcpucycle
CONFIGURE_COMMAND cd ../libcpucycle && ./configure --prefix=${CMAKE_BINARY_DIR}
BUILD_COMMAND cd ../libcpucycle && make
INSTALL_COMMAND cd ../libcpucycle && make install
)

include(CheckCCompilerFlag)
# Check if the same compile family is used for both C and CXX
if(NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
Expand Down Expand Up @@ -669,6 +685,10 @@ if((CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 9)
check_ipo_supported(RESULT ipo_supported OUTPUT error)
endif()

include_directories(
${CMAKE_BINARY_DIR}/include
)

add_library(
SMHasherSupport STATIC
AvalancheTest.cpp
Expand Down Expand Up @@ -770,7 +790,8 @@ endif()

target_link_libraries(SMHasher SMHasherSupport
${HIGHWAY_LIB} ${BLAKE3_LIB} ${AHASH_C_LIB}
${CMAKE_THREAD_LIBS_INIT})
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_BINARY_DIR}/lib/libcpucycles.a)

SET(exectargets ${exectargets} SMHasher)
# add_executable( bittest bittest.cpp )
Expand Down
12 changes: 9 additions & 3 deletions SpeedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <parallel_hashmap/phmap.h>
#include <functional>

#include "cpucycles.h"

#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define ARRAY_END(x) (&(x)[COUNT_OF(x)])

Expand Down Expand Up @@ -275,23 +277,27 @@ void BulkSpeedTest ( pfHash hash, uint32_t seed )
const int trials = 2999;
const int blocksize = 256 * 1024;

printf("Using libcpucycles-%s\n", cpucycles_version());
printf("Bulk speed test - %d-byte keys\n",blocksize);
double sumbpc = 0.0;

volatile double warmup_cycles = SpeedTest(hash,seed,trials,blocksize,0);
long long cpu_cycles = cpucycles_persecond();

for(int align = 7; align >= 0; align--)
{
double cycles = SpeedTest(hash,seed,trials,blocksize,align);

double bestbpc = double(blocksize)/cycles;

double bestbps = (bestbpc * 3000000000.0 / 1048576.0);
printf("Alignment %2d - %6.3f bytes/cycle - %7.2f MiB/sec @ 3 ghz\n",align,bestbpc,bestbps);
double bestbps = (bestbpc * cpu_cycles / 1048576.0) / 100000.0;
printf("Alignment %2d - %6.3f bytes/cycle - %7.2f MiB/sec @ %0.1f GHz\n",
align, bestbpc, bestbps);
sumbpc += bestbpc;
}
sumbpc = sumbpc / 8.0;
printf("Average - %6.3f bytes/cycle - %7.2f MiB/sec @ 3 ghz\n",sumbpc,(sumbpc * 3000000000.0 / 1048576.0));
printf("Average - %6.3f bytes/cycle - %7.2f MiB/sec @ %0.1f GHz\n",
sumbpc, (sumbpc * cpu_cycles / 1048576.0) / 100000.0);
fflush(NULL);
}

Expand Down

0 comments on commit 25e86ae

Please sign in to comment.