Skip to content

Commit

Permalink
Add test for measuring speed of K12
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwerner committed Sep 23, 2024
1 parent 063977e commit ba150c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions test/kangaroo_twelve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#define NO_UEFI

#include "../src/kangaroo_twelve.h"

#include "gtest/gtest.h"

#include <chrono>


TEST(TestCoreK12, PerformanceDigest32Of1GB)
{
constexpr size_t bytesPerGigaByte = 1024 * 1024 * 1024;
constexpr size_t repN = 1;
constexpr size_t inputN = bytesPerGigaByte;
constexpr size_t outputN = 32;

char* inputPtr = new char[inputN];
for (size_t i = 0; i < 100; ++i)
{
unsigned int pos, val;
_rdrand32_step(&pos);
_rdrand32_step(&val);
inputPtr[pos % inputN] = val & 0xff;
}
char outputArray[outputN];

auto startTime = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < repN; ++i)
KangarooTwelve(inputPtr, inputN, outputArray, outputN);
auto durationMilliSec = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime);

double bytePerMilliSec = double(repN * inputN) / double(durationMilliSec.count());
double gigaBytePerSec = bytePerMilliSec * (1000.0 / bytesPerGigaByte);
std::cout << "K12 of 1 GB to 32 Byte digest: " << gigaBytePerSec << " GB/sec = " << 1.0 / gigaBytePerSec << " sec/GB" << std::endl;

delete [] inputPtr;
}
2 changes: 1 addition & 1 deletion test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="contract_core.cpp" />
<ClCompile Include="qpi_collection.cpp" />
<ClCompile Include="kangaroo_twelve.cpp" />
<ClCompile Include="spectrum.cpp" />
<ClCompile Include="stdlib_impl.cpp" />
<ClCompile Include="tx_status_request.cpp" />
Expand Down
1 change: 1 addition & 0 deletions test/test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ClCompile Include="qpi_collection.cpp" />
<ClCompile Include="spectrum.cpp" />
<ClCompile Include="stdlib_impl.cpp" />
<ClCompile Include="kangaroo_twelve.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="score_reference.h" />
Expand Down

0 comments on commit ba150c1

Please sign in to comment.