83 lines
2.6 KiB
C
83 lines
2.6 KiB
C
#include "yespower-arm.c"
|
|
#include <time.h>
|
|
#include <stdio.h>
|
|
#include <pthread.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define NUM_ITERATIONS 1000
|
|
|
|
typedef struct {
|
|
uint32_t *header;
|
|
size_t header_size;
|
|
uint8_t *output;
|
|
int iterations;
|
|
int thread_id;
|
|
double hashes_per_second;
|
|
} ThreadArgs;
|
|
|
|
void *yespower_thread(void *args) {
|
|
ThreadArgs *threadArgs = (ThreadArgs *)args;
|
|
clock_t thread_start = clock();
|
|
|
|
for (int i = 0; i < threadArgs->iterations; i++) {
|
|
int result = yespower_with_arm(threadArgs->header, threadArgs->header_size, threadArgs->output, threadArgs->thread_id);
|
|
if (result != 0) {
|
|
printf("Thread %d: Fehler bei Iteration %d\n", threadArgs->thread_id, i);
|
|
pthread_exit((void *)1);
|
|
}
|
|
}
|
|
|
|
clock_t thread_end = clock();
|
|
double elapsed_time = (double)(thread_end - thread_start) / CLOCKS_PER_SEC;
|
|
threadArgs->hashes_per_second = threadArgs->iterations / elapsed_time;
|
|
|
|
printf("Thread %d: %.2f H/s (%.2f Sekunden)\n", threadArgs->thread_id, threadArgs->hashes_per_second, elapsed_time);
|
|
pthread_exit(NULL);
|
|
}
|
|
|
|
void benchmark_yespower(int num_threads) {
|
|
uint32_t header[6] = {1, 0, 0x12345678, 1672531200, 0x00000FFF, 0};
|
|
uint8_t output[32];
|
|
pthread_t threads[num_threads];
|
|
ThreadArgs threadArgs[num_threads];
|
|
double total_hashes_per_second = 0.0;
|
|
|
|
printf("Benchmark gestartet mit %d Thread(s)...\n", num_threads);
|
|
|
|
clock_t start = clock();
|
|
|
|
for (int t = 0; t < num_threads; t++) {
|
|
threadArgs[t].header = header;
|
|
threadArgs[t].header_size = sizeof(header);
|
|
threadArgs[t].output = output;
|
|
threadArgs[t].iterations = NUM_ITERATIONS / num_threads;
|
|
threadArgs[t].thread_id = t;
|
|
threadArgs[t].hashes_per_second = 0.0;
|
|
|
|
if (pthread_create(&threads[t], NULL, yespower_thread, &threadArgs[t]) != 0) {
|
|
perror("Thread-Erstellung fehlgeschlagen");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
for (int t = 0; t < num_threads; t++) {
|
|
pthread_join(threads[t], NULL);
|
|
total_hashes_per_second += threadArgs[t].hashes_per_second;
|
|
}
|
|
|
|
clock_t end = clock();
|
|
double total_time = (double)(end - start) / CLOCKS_PER_SEC;
|
|
|
|
printf("Gesamte Hashing-Zeit: %.2f Sekunden\n", total_time);
|
|
printf("Gesamte Hashrate: %.2f H/s\n", total_hashes_per_second);
|
|
printf("Durchschnittliche Hashrate pro Thread: %.2f H/s\n", total_hashes_per_second / num_threads);
|
|
}
|
|
|
|
int main() {
|
|
benchmark_yespower(1); // Single Thread Benchmark
|
|
benchmark_yespower(sysconf(_SC_NPROCESSORS_ONLN)); // Multi-Thread Benchmark
|
|
return 0;
|
|
}
|