Skip to content

Commit

Permalink
Merge pull request #117 from chfast/kiss99-tester
Browse files Browse the repository at this point in the history
Add KISS99 distribution tester
  • Loading branch information
chfast authored Dec 10, 2018
2 parents 3f4b4a1 + 687fefc commit 9fc4c0b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ignore:
- "test/benchmarks/*"
- "test/fakeminer/*"
- "test/integration/*"
- "test/tools/*"
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
add_subdirectory(benchmarks)
add_subdirectory(fakeminer)
add_subdirectory(integration)
add_subdirectory(tools)
add_subdirectory(unittests)

if(ETHASH_FUZZING)
Expand Down
8 changes: 8 additions & 0 deletions test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

add_executable(kiss99-tester kiss99_tester.cpp)
target_link_libraries(kiss99-tester PRIVATE ethash)
target_include_directories(kiss99-tester PRIVATE ${ETHASH_PRIVATE_INCLUDE_DIR})
set_target_properties(kiss99-tester PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
46 changes: 46 additions & 0 deletions test/tools/kiss99_tester.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <ethash/kiss99.hpp>
#include <iomanip>
#include <iostream>

int main()
{
constexpr uint32_t mod = 11;
uint64_t histogram[mod] = {};
kiss99 rng;

constexpr uint64_t output_interval = 1000000000;
uint64_t output_point = output_interval;

constexpr double expected = double(1) / mod;

for (uint64_t i = 0; i <= uint64_t(-1); ++i)
{
auto x = rng() % mod;
++histogram[x];

if (i == output_point)
{
std::cout << std::right << std::setw(4) << (i / output_interval)
<< "G:" << std::fixed;

// // Probabilities:
// for (auto h : histogram)
// std::cout << ' ' << std::setw(9) << (double(h) / double(i));
// std::cout << '\n';

// Errors:
for (auto h : histogram)
std::cout << ' ' << std::setw(10) << std::setprecision(6)
<< (double(h) / double(i) - expected) / expected * 10 << '%';
std::cout << '\n';

output_point += output_interval;
}
}

return 0;
}

0 comments on commit 9fc4c0b

Please sign in to comment.