-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from chfast/kiss99-tester
Add KISS99 distribution tester
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ ignore: | |
- "test/benchmarks/*" | ||
- "test/fakeminer/*" | ||
- "test/integration/*" | ||
- "test/tools/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ..) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |