diff --git a/CMakeLists.txt b/CMakeLists.txt index f17b3f13..8cecdc12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)) @@ -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 @@ -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 ) diff --git a/SpeedTest.cpp b/SpeedTest.cpp index 2d8b0eeb..c0aabd1b 100644 --- a/SpeedTest.cpp +++ b/SpeedTest.cpp @@ -14,6 +14,8 @@ #include #include +#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)]) @@ -275,10 +277,12 @@ 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--) { @@ -286,12 +290,14 @@ void BulkSpeedTest ( pfHash hash, uint32_t seed ) 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); }