#include #include #include #include #include #include "../sha256/sha256_backend.h" static double now_seconds(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9; } int main(int argc, char **argv) { uint8_t header_76[76]; sha256d80_midstate_t mid; sha256_state_t states[4]; uint32_t target_words[8]; uint32_t nonce = 0; uint64_t hashes = 0; volatile uint32_t sink = 0; double seconds = 10.0; double t0; int i; if (argc > 1) { seconds = strtod(argv[1], NULL); if (seconds <= 0.0) { seconds = 10.0; } } for (i = 0; i < 76; i++) { header_76[i] = (uint8_t)(i * 13 + 7); } for (i = 0; i < 8; i++) { target_words[i] = 0xFFFFFFFFU; } sha256d80_midstate_init(&mid, header_76); t0 = now_seconds(); while ((now_seconds() - t0) < seconds) { uint32_t mask = sha256d80_scan_4way(&mid, nonce, target_words, states); sink ^= states[0].h[0] ^ states[1].h[0] ^ states[2].h[0] ^ states[3].h[0] ^ mask; nonce += 4U; hashes += 4U; } { double elapsed = now_seconds() - t0; double khs = (double)hashes / elapsed / 1000.0; printf("bench_hash: %.2f kH/s | hashes=%llu | sink=%08x\n", khs, (unsigned long long)hashes, sink); } return 0; }